Skip to content

Commit

Permalink
Refactoring architecture Manage Stone Code Activity (#52)
Browse files Browse the repository at this point in the history
* refactor Manage Stone Code Activity

* compose layout managestonecode screen

* update gitignore

* update layout

* add unit tests to ManageStoneCodeViewModel

* remove DevicesViewModel

* remove  exclude slf4j
  • Loading branch information
laissdj49 authored Sep 4, 2024
1 parent 7fa73e1 commit f22ffbf
Show file tree
Hide file tree
Showing 18 changed files with 586 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ gertec/gertec-keystore.properties
positivo/positivo-keystore.properties
gertec/*.jks
positivo/*.jks
.kotlin
36 changes: 32 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
alias(libs.plugins.compose.compiler)
}
apply from: '../gertec/gertec-signing-config.gradle'
apply from: '../positivo/positivo-signing-config.gradle'

Expand All @@ -23,6 +26,14 @@ android {
versionName "1.0"
}

buildFeatures {
compose true
}

testOptions {
unitTests.returnDefaultValues = true
}

buildTypes {

//Necessary for the functioning of Positivo's signature in debug mode.
Expand All @@ -49,13 +60,31 @@ android {
exclude 'META-INF/client_release.kotlin_module'
}


buildFeatures {
viewBinding true
}
namespace 'br.com.stonesdk.sdkdemo'
}

dependencies {

def composeBom = platform('androidx.compose:compose-bom:2024.06.00')
implementation composeBom
implementation 'androidx.compose.material3:material3'
implementation 'androidx.compose.foundation:foundation'
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.activity:activity-compose:1.9.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.8.3'

implementation("io.insert-koin:koin-core:3.1.6")
implementation("io.insert-koin:koin-android:3.1.6")
implementation("io.insert-koin:koin-androidx-compose:3.1.6")

debugImplementation 'androidx.compose.ui:ui-tooling'
androidTestImplementation composeBom

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.github.permissions-dispatcher:permissionsdispatcher:4.8.0'
Expand All @@ -75,10 +104,9 @@ dependencies {
implementation "androidx.activity:activity-ktx:1.9.1"
implementation "androidx.fragment:fragment-ktx:1.8.2"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

testImplementation "io.mockk:mockk:1.13.12"
testImplementation "org.junit.platform:junit-platform-launcher:1.10.0"
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.10.0"
testImplementation "org.junit.vintage:junit-vintage-engine:5.10.0"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0-RC"
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
android:name=".activities.PosTransactionActivity"
android:label="@string/title_activity_transaction" />
<activity
android:name=".activities.ManageStoneCodeActivity"
android:name=".activities.manageStoneCode.ManageStoneCodeActivity"
android:label="@string/title_activity_manage_stone_codes" />
</application>

Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/br/com/stonesdk/sdkdemo/DI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package br.com.stonesdk.sdkdemo

import br.com.stonesdk.sdkdemo.activities.manageStoneCode.ActivationProviderWrapper
import br.com.stonesdk.sdkdemo.activities.manageStoneCode.ManageStoneCodeViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module
import stone.application.SessionApplication
import stone.providers.ActiveApplicationProvider
import stone.utils.Stone

val demoApplicationModule = module {

factory<SessionApplication> {
Stone.sessionApplication
}

factory<ActivationProviderWrapper> {
ActivationProviderWrapper(get())
}

viewModel {
ManageStoneCodeViewModel(get(), get())
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/br/com/stonesdk/sdkdemo/FeatureFlag.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package br.com.stonesdk.sdkdemo

object FeatureFlag {
const val composeRefactorEnabled = true
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package br.com.stonesdk.sdkdemo.activities

import android.app.Application
import br.com.stonesdk.sdkdemo.demoApplicationModule
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.GlobalContext.startKoin
import stone.application.StoneStart


class DemoApplication : Application() {

override fun onCreate() {
super.onCreate()
StoneStart.init(this)
startKoin {
androidContext(this@DemoApplication)
modules(demoApplicationModule)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.appcompat.app.AppCompatActivity
import br.com.stone.posandroid.providers.PosPrintProvider
import br.com.stone.posandroid.providers.PosValidateTransactionByCardProvider
import br.com.stonesdk.sdkdemo.R
import br.com.stonesdk.sdkdemo.activities.manageStoneCode.ManageStoneCodeActivity
import br.com.stonesdk.sdkdemo.databinding.ActivityMainBinding
import stone.application.enums.Action
import stone.application.interfaces.StoneActionCallback
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package br.com.stonesdk.sdkdemo.activities.manageStoneCode

import android.content.Context
import kotlinx.coroutines.suspendCancellableCoroutine
import stone.application.interfaces.StoneCallbackInterface
import stone.providers.ActiveApplicationProvider
import kotlin.coroutines.resume

class ActivationProviderWrapper(
private val context: Context
) {

suspend fun activate(stoneCode: String): Boolean = suspendCancellableCoroutine { continuation ->
val provider = newProvider()

provider.connectionCallback = object : StoneCallbackInterface {
override fun onSuccess() {
continuation.resume(true)
}

override fun onError() {
continuation.resume(false)
}
}

provider.activate(stoneCode)

continuation.invokeOnCancellation {}
}

suspend fun deactivate(stoneCode: String): Boolean =
suspendCancellableCoroutine { continuation ->
val provider = newProvider()

provider.connectionCallback = object : StoneCallbackInterface {
override fun onSuccess() {
continuation.resume(true)
}

override fun onError() {
continuation.resume(false)
}
}

provider.deactivate(stoneCode)

continuation.invokeOnCancellation {}
}

fun newProvider() = ActiveApplicationProvider(context)
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package br.com.stonesdk.sdkdemo.activities
package br.com.stonesdk.sdkdemo.activities.manageStoneCode

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.AdapterView.OnItemClickListener
import android.widget.ArrayAdapter
import android.widget.EditText
import android.widget.ListView
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material3.MaterialTheme
import br.com.stonesdk.sdkdemo.FeatureFlag
import br.com.stonesdk.sdkdemo.R
import br.com.stonesdk.sdkdemo.databinding.ActivityMainBinding
import br.com.stonesdk.sdkdemo.databinding.ActivityManageStoneCodeBinding
import stone.application.interfaces.StoneCallbackInterface
import stone.providers.ActiveApplicationProvider
import stone.user.UserModel
import stone.utils.Stone

/**
* @author tiago.barbosa
* @since 10/04/2018
*/
class ManageStoneCodeActivity : AppCompatActivity() {

private lateinit var binding: ActivityManageStoneCodeBinding
Expand All @@ -30,7 +27,18 @@ class ManageStoneCodeActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (FeatureFlag.composeRefactorEnabled) {
setContent {
MaterialTheme {
ManageStoneCodeScreen()
}
}
} else {
onCreateConfig()
}
}

private fun onCreateConfig() {
binding = ActivityManageStoneCodeBinding.inflate(layoutInflater)
setContentView(binding.root)

Expand Down
Loading

0 comments on commit f22ffbf

Please sign in to comment.