Skip to content

Commit

Permalink
Adaptive SDK v1.0.2-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrisFuturae committed Oct 3, 2023
1 parent fa4245b commit a37aaa2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This is the Futurae adaptive SDK for Android. The Adaptive SDK is a data collection SDK that can be used stand-alone or together with Futurae SDK.

### Installation

In your application `build.gradle` file add:
```
repositories {
Expand All @@ -19,6 +20,7 @@ dependencies {
implementation 'com.futurae.sdk:adaptive:x.x.x'
}
```

### User guide

For usage instructions together with [Futurae SDK](https://github.com/Futurae-Technologies/android-sdk) please refer to the [Futurae adaptive SDK guide](https://www.futurae.com/docs/guide/futurae-sdks/mobile-sdk/).
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ plugins {

android {
namespace 'com.futurae.adaptivedemo'
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "com.futurae.adaptivedemo"
minSdk 23
targetSdk 33
targetSdk 34
versionCode 1
versionName "1.0.1-alpha"
versionName "1.0.2-alpha"
}

buildFeatures {
Expand All @@ -40,7 +40,7 @@ android {
}

dependencies {
implementation 'com.futurae.sdk:adaptive:1.0.1-alpha'
implementation 'com.futurae.sdk:adaptive:1.0.2-alpha'
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.activity:activity-compose:1.7.2'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/futurae/adaptivedemo/AdaptiveApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AdaptiveApp : Application() {

override fun onCreate() {
super.onCreate()
AdaptiveSDK.INSTANCE.init(this)
AdaptiveSDK.init(this)
Timber.plant(Timber.DebugTree())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ class CollectionsActivity : AppCompatActivity() {
}

lifecycleScope.launch {
AdaptiveDbHelper.INSTANCE.allCollections.collect {
AdaptiveDbHelper.getAllCollections().collect {
collectionsAdapter.submitList(it.toList())
}
}

}
}

Expand Down
54 changes: 33 additions & 21 deletions app/src/main/java/com/futurae/adaptivedemo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.futurae.sdk.adaptive.AdaptiveSDK
import com.futurae.sdk.adaptive.CompletionCallback
import com.futurae.sdk.adaptive.UpdateCallback
import com.futurae.sdk.adaptive.exception.AdaptiveException
import com.futurae.sdk.adaptive.model.AdaptiveCollection
import com.google.android.material.slider.Slider
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -44,14 +45,19 @@ class MainActivity : AppCompatActivity() {
}
}

private val completionCallback = CompletionCallback {
Toast.makeText(this@MainActivity, "Collection complete", Toast.LENGTH_SHORT).show()
lifecycleScope.launch(Dispatchers.IO) {
AdaptiveDbHelper.INSTANCE.insertCollection(it)
private val completionCallback = object : CompletionCallback {

override fun onCollectionCompleted(data: AdaptiveCollection) {
Toast.makeText(this@MainActivity, "Collection complete", Toast.LENGTH_SHORT).show()
lifecycleScope.launch(Dispatchers.IO) {
AdaptiveDbHelper.insertCollection(data)
}
}
}
private val updateCallback = UpdateCallback {
//
private val updateCallback = object: UpdateCallback {
override fun onCollectionDataUpdated(data: AdaptiveCollection) {
//no-op
}
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -65,31 +71,37 @@ class MainActivity : AppCompatActivity() {

binding.statusTextview.text = getString(R.string.status_formatter, getString(R.string.status_idle))
binding.buttonEnable.text =
if (AdaptiveSDK.INSTANCE.isEnabled) getString(R.string.button_disable_adaptive)
if (AdaptiveSDK.isEnabled()) getString(R.string.button_disable_adaptive)
else getString(R.string.button_enable_adaptive)
binding.buttonEnable.setOnClickListener {
if (!AdaptiveSDK.INSTANCE.isEnabled) {
AdaptiveSDK.INSTANCE.enable(applicationContext as AdaptiveApp, updateCallback, completionCallback)
if (!AdaptiveSDK.isEnabled()) {
AdaptiveSDK.enable(applicationContext as AdaptiveApp, updateCallback, completionCallback)
binding.buttonEnable.text = getString(R.string.button_disable_adaptive)
} else {
AdaptiveSDK.INSTANCE.disable()
AdaptiveSDK.disable()
binding.buttonEnable.text = getString(R.string.button_enable_adaptive)
}
}
binding.buttonRequestCollection.setOnClickListener {
try {
AdaptiveSDK.INSTANCE.requestAdaptiveCollection(
UpdateCallback {
lifecycleScope.launch(Dispatchers.Main) {
binding.statusTextview.text =
getString(R.string.status_formatter, getString(R.string.status_collecting))
AdaptiveSDK.requestAdaptiveCollection(
object : UpdateCallback {
override fun onCollectionDataUpdated(data: AdaptiveCollection) {
lifecycleScope.launch(Dispatchers.Main) {
binding.statusTextview.text =
getString(R.string.status_formatter, getString(R.string.status_collecting))
}
}

},
CompletionCallback {
lifecycleScope.launch(Dispatchers.Main) {
binding.statusTextview.text =
getString(R.string.status_formatter, getString(R.string.status_idle))
object : CompletionCallback {
override fun onCollectionCompleted(data: AdaptiveCollection) {
lifecycleScope.launch(Dispatchers.Main) {
binding.statusTextview.text =
getString(R.string.status_formatter, getString(R.string.status_idle))
}
}

},
true
)
Expand All @@ -106,7 +118,7 @@ class MainActivity : AppCompatActivity() {
}
binding.buttonConfigureThreshold.setOnClickListener {
try {
var sliderValue = AdaptiveSDK.INSTANCE.adaptiveCollectionThreshold
var sliderValue = AdaptiveSDK.getAdaptiveCollectionThreshold()
val dialogView = layoutInflater.inflate(R.layout.dialog_adaptive_threshold, null)
val textValue = dialogView.findViewById<TextView>(R.id.sliderValue).apply {
text = "$sliderValue sec"
Expand All @@ -122,7 +134,7 @@ class MainActivity : AppCompatActivity() {
.setTitle("Adaptive time threshold").setView(dialogView)
.setPositiveButton("OK") { _, _ ->
try {
AdaptiveSDK.INSTANCE.adaptiveCollectionThreshold = sliderValue
AdaptiveSDK.setAdaptiveCollectionThreshold(sliderValue)
} catch (e: AdaptiveException) {
Timber.e(e)
Toast.makeText(this, e.message, Toast.LENGTH_SHORT).show()
Expand Down

0 comments on commit a37aaa2

Please sign in to comment.