Skip to content

Commit

Permalink
Update SDK to version 6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquenfaria committed Jul 8, 2021
1 parent 449ffed commit 048cafa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// MOTIONTAG SDK changelog: https://api.motion-tag.de/developer/android_changelog
implementation "de.motiontag:tracker:5.5.1"
implementation "de.motiontag:tracker:6.0.0"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "androidx.appcompat:appcompat:1.3.0"
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/de/motiontag/sampleapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ private const val SETTINGS_REQUEST_CODE = 200

class MainActivity : AppCompatActivity() {

private val motionTag: MotionTag by lazy { MotionTag.getInstance() }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand Down Expand Up @@ -53,7 +55,7 @@ class MainActivity : AppCompatActivity() {

private fun setTrackingListener() {
trackingButton.setOnClickListener {
if (MotionTag.isTrackingActive()) {
if (motionTag.isTrackingActive()) {
stopTracking()
} else {
checkSettingsAndPermissions()
Expand All @@ -62,31 +64,32 @@ class MainActivity : AppCompatActivity() {
}

private fun checkSettingsAndPermissions() {
if (!MotionTag.hasRequiredLocationSettings()) {
if (!motionTag.hasRequiredLocationSettings()) {
requestLocationSettings()
} else if (!MotionTag.hasRequiredPermissions()) {
} else if (!motionTag.hasRequiredPermissions()) {
requestPermissionsOrShowRationale(this, PERMISSIONS_REQUEST_CODE)
} else {
startTracking()
}
}

private fun requestLocationSettings() {
MotionTag.requestRequiredLocationSettings(this, SETTINGS_REQUEST_CODE)
motionTag.requestRequiredLocationSettings(this, SETTINGS_REQUEST_CODE)
}

private fun stopTracking() {
MotionTag.stop()
motionTag.stop()
updateTrackingButton()
}

private fun startTracking() {
MotionTag.start(USER_TOKEN)
motionTag.userToken(USER_TOKEN)
motionTag.start()
updateTrackingButton()
}

private fun updateTrackingButton() {
if (MotionTag.isTrackingActive()) {
if (motionTag.isTrackingActive()) {
trackingButton.text = getString(R.string.stop_tracking)
trackingButton.setBackgroundColor(ContextCompat.getColor(this, R.color.red))
} else {
Expand Down
7 changes: 2 additions & 5 deletions app/src/main/java/de/motiontag/sampleapp/SampleApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ class SampleApp : Application(), MotionTag.Callback {
super.onCreate()

val notification = getForegroundNotification()
val settings = Settings.Builder()
.notification(notification)
.useWifiOnlyDataTransfer(true)
.build()
MotionTag.with(this, settings, this)
val settings = Settings(notification, isWifiOnlyDataTransfer = false)
MotionTag.getInstance().initialize(this, settings, this)
}

override fun onEvent(event: Event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private fun Activity.getPermissionsToRationale(): List<String> {
}

private fun Activity.getPermissions(): List<String> {
val permissions = MotionTag.getDeniedRequiredPermissions()
val permissions = MotionTag.getInstance().getDeniedRequiredPermissions()
return if (isAllowedToRequestBackgroundLocation()) {
permissions
} else {
Expand Down

0 comments on commit 048cafa

Please sign in to comment.