Skip to content

Commit

Permalink
Merge branch 'jensck/ch40227/add-boolean-support-to-sdk'
Browse files Browse the repository at this point in the history
  • Loading branch information
jensck committed Nov 21, 2019
2 parents a056833 + 6036291 commit dee374c
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 109 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
}

dependencies {
classpath 'io.fabric.tools:gradle:1.31.0'
classpath 'io.fabric.tools:gradle:1.31.2'
}
}

Expand Down Expand Up @@ -95,9 +95,9 @@ dependencies {
// implemented by hand (and as such, might not be worth it.)
implementation 'com.getbase:floatingactionbutton:1.10.1'

releaseImplementation 'com.google.firebase:firebase-core:17.2.0'
releaseImplementation 'com.google.firebase:firebase-analytics:17.2.0'
releaseImplementation 'com.google.firebase:firebase-perf:19.0.0'
releaseImplementation 'com.google.firebase:firebase-core:17.2.1'
releaseImplementation 'com.google.firebase:firebase-analytics:17.2.1'
releaseImplementation 'com.google.firebase:firebase-perf:19.0.2'
releaseImplementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'

// Segment
Expand Down Expand Up @@ -144,4 +144,4 @@ dependencies {
testImplementation 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services' /* uncomment for release builds */
//apply plugin: 'com.google.gms.google-services' /* uncomment for release builds */
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.app.Application
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.util.Log
import io.particle.android.sdk.cloud.ParticleCloudSDK
import io.particle.android.sdk.devicesetup.BuildConfig
import io.particle.android.sdk.devicesetup.ParticleDeviceSetupLibrary
import io.particle.android.sdk.onApplicationCreated
Expand Down Expand Up @@ -38,6 +40,11 @@ class TinkerApplication : Application() {
"OS version=${Build.VERSION.RELEASE},\n" +
"App version=$appVersionName,"
}

// Use `Log` class to only log this to the system log, and not the separate logs we store
// on disk for export on user request
val last4 = ParticleCloudSDK.getCloud().accessToken?.takeLast(4) ?: "No token stored yet!"
Log.i("ParticleAuth", "Last 4 digits of auth token: $last4")
}
}

Expand Down
23 changes: 12 additions & 11 deletions app/src/main/java/io/particle/android/sdk/ui/EventsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.core.content.getSystemService
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearSmoothScroller
Expand Down Expand Up @@ -218,8 +217,8 @@ class EventsFragment : Fragment() {
}

private class Event internal constructor(
internal var name: String,
internal var particleEvent: ParticleEvent
internal var name: String?,
internal var particleEvent: ParticleEvent?
)

private class EventListAdapter : RecyclerView.Adapter<EventListAdapter.ViewHolder>() {
Expand Down Expand Up @@ -250,10 +249,11 @@ class EventsFragment : Fragment() {

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val event = filteredData[position]

holder.eventName.text = event.name
holder.eventData.text = event.particleEvent.dataPayload
holder.eventData.text = event.particleEvent?.dataPayload
holder.eventTime.text = SimpleDateFormat("MMM dd, yyyy HH:mm:ss", Locale.getDefault())
.format(event.particleEvent.publishedAt)
.format(event.particleEvent?.publishedAt)

holder.copyButton.setOnClickListener { _ ->
val context = holder.itemView.context
Expand All @@ -269,14 +269,14 @@ class EventsFragment : Fragment() {
val jsonObject = JSONObject()
try {
jsonObject.put("Event", event.name)
jsonObject.put("DeviceID", event.particleEvent.deviceId)
jsonObject.put("Data", event.particleEvent.dataPayload)
jsonObject.put("DeviceID", event.particleEvent?.deviceId)
jsonObject.put("Data", event.particleEvent?.dataPayload)
val dateTime = SimpleDateFormat(
"yyyy-MM-dd HH:mm::ssZ",
Locale.getDefault()
).format(event.particleEvent.publishedAt)
).format(event.particleEvent?.publishedAt)
jsonObject.put("Time", dateTime)
jsonObject.put("TTL", event.particleEvent.timeToLive)
jsonObject.put("TTL", event.particleEvent?.timeToLive)
} catch (ignore: JSONException) {
}

Expand All @@ -291,7 +291,7 @@ class EventsFragment : Fragment() {

fun add(event: Event) {
data.add(0, event)
if (event.name.contains(filter)) {
if (event.name?.contains(filter) == true) {
filteredData.add(0, event)
notifyItemInserted(0)
}
Expand All @@ -303,7 +303,8 @@ class EventsFragment : Fragment() {
notifyDataSetChanged()

for (event in data) {
if (event.name.contains(filter) || event.particleEvent.dataPayload.contains(filter)) {
if (event.name?.contains(filter) == true
|| event.particleEvent?.dataPayload?.contains(filter) == true) {
filteredData.add(event)
notifyItemInserted(data.indexOf(event))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,16 @@ private class DataListAdapter(
override fun callApi(particleDevice: ParticleDevice): String {
return try {
if (variable.variableType === VariableType.INT) {
// sometimes ints are serialized as floats, sometimes they're
// serialized as actual ints. Depends on size, I guess? ¯\_(ツ)_/¯
val value = device.getVariable(variable.name).toString()
val dotIndex = value.indexOf(".")
value.substring(
0,
if (dotIndex > 0) dotIndex else value.length
)
value.toFloat().toInt().toString()
} else {
device.getVariable(variable.name).toString()
}
} catch (e: ParticleDevice.VariableDoesNotExistException) {
throw ParticleCloudException(e)
}

}

override fun onSuccess(value: String) {
Expand Down Expand Up @@ -391,6 +388,7 @@ private class DataListAdapter(
VariableType.INT -> "(Integer)"
VariableType.DOUBLE -> "(Double)"
VariableType.STRING -> "(String)"
VariableType.BOOLEAN -> "(Boolean)"
}
holder.type.text = type
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ class InspectorActivity : BaseActivity() {
return
}

device = intent.getParcelableExtra(EXTRA_DEVICE)

setContentView(R.layout.activity_inspector)

device = intent.getParcelableExtra(EXTRA_DEVICE)

// Show the Up button in the action bar.
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowTitleEnabled(true)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

buildscript {

ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.3.60'

repositories {
google()
Expand Down
10 changes: 10 additions & 0 deletions cloudsdk/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
1.0.0
=====
* Add support for boolean variables
* Remove requestPasswordResetForCustomer() since this functionality has been removed from the
Particle Cloud
* Change nullability contract of ParticleEvent to reflect that almost anything can be null
* Bump to 1.0.0, both to signify that we are no longer considered beta, and because this release
makes a couple breaking changes.


0.5.1
=====
* New features - Two factor authentication.
Expand Down
8 changes: 1 addition & 7 deletions cloudsdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {


// This is the library version used when deploying the artifact
version = '0.5.1'
version = '1.0.0'

ext {
bintrayRepo = 'android'
Expand Down Expand Up @@ -62,12 +62,6 @@ android {
}
}

buildTypes {
debug {
testCoverageEnabled = true
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand Down
15 changes: 0 additions & 15 deletions cloudsdk/src/main/java/io/particle/android/sdk/cloud/ApiDefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,5 @@ class ApiDefs {
@POST("/v1/user/password-reset")
fun requestPasswordReset(@Field("username") email: String): Response

@FormUrlEncoded
@POST("/v1/products/{productId}/customers/reset_password")
fun requestPasswordResetForCustomer(
@Field("email") email: String,
@Path("productId") productId: Int?
): Response

@FormUrlEncoded
@POST("/v1/orgs/{orgName}/customers/reset_password")
@Deprecated("")
fun requestPasswordResetForCustomer(
@Field("email") email: String,
@Path("orgName") orgName: String
): Response

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,26 +409,6 @@ class ParticleCloud internal constructor(
} catch (error: RetrofitError) {
throw ParticleCloudException(error)
}

}

@WorkerThread
@Throws(ParticleCloudException::class)
fun requestPasswordResetForCustomer(email: String, productId: Int) {
return runHandlingCommonErrors {
identityApi.requestPasswordResetForCustomer(email, productId)
}
}

@WorkerThread
@Deprecated("")
@Throws(ParticleCloudException::class)
fun requestPasswordResetForCustomer(email: String, organizationSlug: String) {
return runHandlingCommonErrors {
log.w("Use product id instead of organization slug.")
@Suppress("DEPRECATION")
identityApi.requestPasswordResetForCustomer(email, organizationSlug)
}
}

@WorkerThread
Expand Down Expand Up @@ -1060,6 +1040,7 @@ class ParticleCloud internal constructor(
"int32" -> VariableType.INT
"double" -> VariableType.DOUBLE
"string" -> VariableType.STRING
"bool" -> VariableType.BOOLEAN
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ class ParticleDevice internal constructor(
enum class VariableType {
INT,
DOUBLE,
STRING
STRING,
BOOLEAN
}


Expand Down Expand Up @@ -569,12 +570,16 @@ class ParticleDevice internal constructor(
val eventBus = EventBus.getDefault()
subscriptions.add(
subscribeToSystemEvent("spark/status") { _, particleEvent ->
sendUpdateStatusChange(eventBus, particleEvent.dataPayload)
particleEvent.dataPayload?.let {
sendUpdateStatusChange(eventBus, particleEvent.dataPayload)
}
}
)
subscriptions.add(
subscribeToSystemEvent("spark/flash/status") { _, particleEvent ->
sendUpdateFlashChange(eventBus, particleEvent.dataPayload)
particleEvent.dataPayload?.let {
sendUpdateFlashChange(eventBus, particleEvent.dataPayload)
}
}
)
subscriptions.add(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.particle.android.sdk.cloud

import com.google.gson.annotations.SerializedName
import java.util.*
import javax.annotation.ParametersAreNonnullByDefault

// Normally it's bad form to use network data models as API data models, but considering that
// for the moment, they'd be a 1:1 mapping, we'll just reuse this data model class. If the
// network API changes, then we can write new classes for the network API models, without
// impacting the public API of the SDK.
@ParametersAreNonnullByDefault
class ParticleEvent(
@SerializedName("coreid") val deviceId: String,
@SerializedName("data") val dataPayload: String?,
@SerializedName("published_at") val publishedAt: Date,
@SerializedName("ttl") val timeToLive: Int?
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ object Toaster {
*
* This is safe to call from background/worker threads.
*/
@JvmStatic
fun s(activity: Activity, msg: String?) {
showToast(activity, msg, Toast.LENGTH_SHORT)
}
Expand All @@ -29,6 +30,7 @@ object Toaster {
*
* This is safe to call from background/worker threads.
*/
@JvmStatic
fun l(activity: Activity, msg: String?) {
showToast(activity, msg, Toast.LENGTH_LONG)
}
Expand Down
2 changes: 1 addition & 1 deletion devicesetup/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

implementation project(':cloudsdk')
//api 'io.particle:cloudsdk:0.4.9'
// api 'io.particle:cloudsdk:1.0.0'

api 'com.squareup.phrase:phrase:1.1.0'
api 'uk.co.chrisjenx:calligraphy:2.3.0'
Expand Down
7 changes: 4 additions & 3 deletions sdk_example_app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ dependencies {
//
// comment out the above, and
// UNCOMMENT THE FOLLOWING TO USE A PUBLISHED VERSION OF THE SDK:
// implementation 'io.particle:cloudsdk:0.3.3'
// implementation 'io.particle:cloudsdk:1.0.0'

implementation 'androidx.fragment:fragment:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.fragment:fragment:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'org.greenrobot:eventbus:3.0.0'
}

0 comments on commit dee374c

Please sign in to comment.