-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring architecture Manage Stone Code Activity (#52)
* 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
Showing
18 changed files
with
586 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ gertec/gertec-keystore.properties | |
positivo/positivo-keystore.properties | ||
gertec/*.jks | ||
positivo/*.jks | ||
.kotlin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
8 changes: 7 additions & 1 deletion
8
app/src/main/java/br/com/stonesdk/sdkdemo/activities/DemoApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...main/java/br/com/stonesdk/sdkdemo/activities/manageStoneCode/ActivationProviderWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.