Skip to content

Commit

Permalink
PR review comments solved
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-meli committed Jun 2, 2023
1 parent 4ecd195 commit 0f21b5f
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ sealed class PrinterEvents {
class OutputResult(val resultMessage: String) : PrinterEvents()
class LaunchPrinterSelector(val printerList: List<BluetoothDeviceModel>) : PrinterEvents()
object DataEmpty : PrinterEvents()

class Error(val error: Exception) : PrinterEvents()
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ class PrinterTestActivity : AppCompatActivity(), PrinterSelectorCallback {
is PrinterEvents.IsLoading -> binding.progressIndicator.isVisible = event.isVisible
is PrinterEvents.LaunchPrinterSelector -> PrinterSelectorDialog.newInstance(event.printerList)
.show(supportFragmentManager, PrinterSelectorDialog::class.simpleName)

is PrinterEvents.OutputResult -> makeSnackBar(event.resultMessage)
PrinterEvents.DataEmpty -> makeSnackBar(getString(R.string.point_mainapp_demo_app_error_msg_data_empty))
is PrinterEvents.DataEmpty -> makeSnackBar(getString(R.string.point_mainapp_demo_app_error_msg_data_empty))
is PrinterEvents.Error -> event.error.message?.let { message -> makeSnackBar(message) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mercadolibre.android.point_integration_sdk.nativesdk.MPManager
import com.mercadolibre.android.point_integration_sdk.nativesdk.bluetoothclient.provider.contracts.states.BluetoothPrinterResult
import com.mercadolibre.android.point_integration_sdk.nativesdk.message.utils.doIfError
import com.mercadolibre.android.point_integration_sdk.nativesdk.message.utils.doIfSuccess
import com.mercadolibre.android.point_mainapp_demo.app.view.bluetooth.contracts.PrinterEvents
import kotlinx.coroutines.Dispatchers
Expand All @@ -29,14 +30,20 @@ class BluetoothPrinterViewModel : ViewModel() {
viewModelScope.launch(Dispatchers.IO) {
addressDevices?.let { address ->
MPManager.bluetooth.printer.makePrint(stringToPrint, address) { response ->
response.doIfSuccess { result ->
resultBehavior(result)
}
response
.doIfSuccess { result ->
resultBehavior(result)
}.doIfError { exception ->
_printerEventLiveDataLiveData.value = PrinterEvents.Error(exception)
}
}
} ?: MPManager.bluetooth.printer.makePrint(stringToPrint) { response ->
response.doIfSuccess { result ->
resultBehavior(result)
}
response
.doIfSuccess { result ->
resultBehavior(result)
}.doIfError { exception ->
_printerEventLiveDataLiveData.value = PrinterEvents.Error(exception)
}
}
}
}
Expand All @@ -46,9 +53,12 @@ class BluetoothPrinterViewModel : ViewModel() {
_printerEventLiveDataLiveData.postValue(PrinterEvents.IsLoading(false))
if (makePrintResult == BluetoothPrinterResult.NEED_SELECTION_DEVICE) {
MPManager.bluetooth.discover.getPairPrinterDevices { response ->
response.doIfSuccess { listPrinter ->
_printerEventLiveDataLiveData.postValue(PrinterEvents.LaunchPrinterSelector(listPrinter))
}
response
.doIfSuccess { listPrinter ->
_printerEventLiveDataLiveData.postValue(PrinterEvents.LaunchPrinterSelector(listPrinter))
}.doIfError { exception ->
_printerEventLiveDataLiveData.value = PrinterEvents.Error(exception)
}
}
} else {
_printerEventLiveDataLiveData.postValue(PrinterEvents.OutputResult(makePrintResult.name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.viewModelScope
import com.mercadolibre.android.point_integration_sdk.nativesdk.MPManager
import com.mercadolibre.android.point_integration_sdk.nativesdk.bluetoothclient.provider.contracts.states.DiscoveryEventsResult
import com.mercadolibre.android.point_integration_sdk.nativesdk.bluetoothclient.provider.entities.BluetoothDeviceModel
import com.mercadolibre.android.point_integration_sdk.nativesdk.message.utils.doIfError
import com.mercadolibre.android.point_integration_sdk.nativesdk.message.utils.doIfSuccess
import com.mercadolibre.android.point_mainapp_demo.app.view.bluetooth.contracts.BluetoothSettingsEvents
import kotlinx.coroutines.Dispatchers
Expand All @@ -21,35 +22,48 @@ internal class BluetoothSettingsViewModel : ViewModel() {

fun registerConnectObserver() {
MPManager.bluetooth.connectObserver.registerObserver { result ->
result.doIfSuccess { pair ->
val bluetoothDeviceModel = pair.first
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.ConnectDevicesResult(bluetoothDeviceModel)
}
result
.doIfSuccess { pair ->
val bluetoothDeviceModel = pair.first
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.ConnectDevicesResult(bluetoothDeviceModel)
}.doIfError { exception ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.Error(exception)
}
}
}

fun getCurrentStateBluetooth() {
MPManager.bluetooth.ignitor.getCurrentState { response ->
response.doIfSuccess { result ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.IgnitorCurrentState(result)
}
response
.doIfSuccess { result ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.IgnitorCurrentState(result)
}.doIfError { exception ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.Error(exception)
}
}
}

fun ignitorBluetooth(ignitor: Boolean) {
MPManager.bluetooth.ignitor.run {
if (ignitor) {
turnOn { response ->
response.doIfSuccess { result ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.IgnitorLaunchResult(result)
}

response
.doIfSuccess { result ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.IgnitorLaunchResult(result)
}
.doIfError { exception ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.Error(exception)
}
}
} else {
turnOff { response ->
response.doIfSuccess { result ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.IgnitorLaunchResult(result)
}
response
.doIfSuccess { result ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.IgnitorLaunchResult(result)
}
.doIfError { exception ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.Error(exception)
}
}
}
}
Expand All @@ -58,9 +72,13 @@ internal class BluetoothSettingsViewModel : ViewModel() {
fun getPairDevices() {
viewModelScope.launch(Dispatchers.IO) {
MPManager.bluetooth.discover.getPairDevices { response ->
response.doIfSuccess { result ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.DiscoveryPairDevicesResult(result)
}
response
.doIfSuccess { result ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.DiscoveryPairDevicesResult(result)
}
.doIfError { exception ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.Error(exception)
}
}
}
}
Expand Down Expand Up @@ -97,17 +115,24 @@ internal class BluetoothSettingsViewModel : ViewModel() {
viewModelScope.launch(Dispatchers.IO) {
if (needPair) {
MPManager.bluetooth.paring.pairDevices(address) { response ->
response.doIfSuccess { resultPair ->
Log.i(TAG, "pairDevices: callback response ${resultPair.first}")
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.PairingDevicesStatus(resultPair)
}
response
.doIfSuccess { resultPair ->
Log.i(TAG, "pairDevices: callback response ${resultPair.first}")
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.PairingDevicesStatus(resultPair)
}
.doIfError { exception ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.Error(exception)
}
}
} else {
MPManager.bluetooth.paring.unPairDevices(address) { response ->
response.doIfSuccess { resultPair ->
Log.i(TAG, "unPairDevices: callback response ${resultPair.first}")
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.PairingDevicesStatus(resultPair)
}
response
.doIfSuccess { resultPair ->
Log.i(TAG, "unPairDevices: callback response ${resultPair.first}")
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.PairingDevicesStatus(resultPair)
}.doIfError { exception ->
_bluetoothSettingLiveData.value = BluetoothSettingsEvents.Error(exception)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
android:text="@string/point_mainapp_demo_app_smart_info_main_title"
android:textAllCaps="false"
app:cornerRadius="@dimen/ui_1_25m"
app:icon="@drawable/point_mainapp_demo_app_ic_qr_code"
app:icon="@drawable/point_mainapp_demo_app_ic_info"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/point_mainapp_demo_app_go_to_camera_scanner" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@
android:layout_height="match_parent"
android:background="@color/primaryLightColor"
android:padding="@dimen/ui_3m"
tools:context=".view.info.SmartInfoActivity"
tools:ignore="ResourceName">
tools:context=".view.info.SmartInfoActivity">

<TextView
android:id="@+id/point_mainapp_demo_app_smart_info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/ui_3m"
android:text="@string/point_mainapp_demo_app_smart_info_title"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/mainapp_demo_app_serial_number_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/ui_2m"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@id/point_mainapp_demo_app_smart_info_title" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/mainapp_demo_app_brand_name_text"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@
<string name="point_mainapp_demo_app_brand_name_text">Brand name: %s</string>
<string name="point_mainapp_demo_app_model_name_text">Model name: %s</string>
<string name="point_mainapp_demo_app_sdk_version_text">SDK version: %s</string>
<string name="point_mainapp_demo_app_smart_info_title">Smart info</string>
</resources>

0 comments on commit 0f21b5f

Please sign in to comment.