Enabled StrictMode | Fixed Multiple DB object creation | Chuck for Pulse
This commit is contained in:
@@ -6,14 +6,34 @@
|
||||
|
||||
package com.naviapp.app
|
||||
|
||||
import android.os.StrictMode
|
||||
import android.text.TextUtils
|
||||
import androidx.multidex.MultiDexApplication
|
||||
import com.naviapp.BuildConfig
|
||||
import com.naviapp.analytics.utils.NaviTrackEvent
|
||||
import com.naviapp.utils.DEV
|
||||
import timber.log.Timber
|
||||
|
||||
class NaviApplication : MultiDexApplication() {
|
||||
|
||||
override fun onCreate() {
|
||||
if (TextUtils.equals(BuildConfig.FLAVOR, DEV) && BuildConfig.DEBUG) {
|
||||
StrictMode.setThreadPolicy(
|
||||
StrictMode.ThreadPolicy.Builder()
|
||||
.detectDiskReads()
|
||||
.detectDiskWrites()
|
||||
.detectNetwork() // or .detectAll() for all detectable problems
|
||||
.penaltyLog()
|
||||
.build()
|
||||
)
|
||||
StrictMode.setVmPolicy(
|
||||
StrictMode.VmPolicy.Builder()
|
||||
.detectLeakedSqlLiteObjects()
|
||||
.detectLeakedClosableObjects()
|
||||
.penaltyLog()
|
||||
.build()
|
||||
)
|
||||
}
|
||||
super.onCreate()
|
||||
instance = this
|
||||
if (BuildConfig.DEBUG) {
|
||||
|
||||
@@ -24,4 +24,5 @@ const val ICON_UPI_ID = "UPI_ID"
|
||||
const val ICON_UPI_DETAILS = "UPI_DETAILS"
|
||||
const val PROD = "prod"
|
||||
const val QA = "qa"
|
||||
const val DEV = "dev"
|
||||
const val COUNTRY_ISO = "IN"
|
||||
@@ -52,10 +52,13 @@ dependencies {
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
|
||||
implementation 'com.squareup.okhttp3:logging-interceptor:4.8.0'
|
||||
debugImplementation 'com.readystatesoftware.chuck:library:1.1.0'
|
||||
releaseImplementation 'com.readystatesoftware.chuck:library-no-op:1.1.0'
|
||||
|
||||
// optional - Test helpers
|
||||
testImplementation "androidx.room:room-testing:2.3.0"
|
||||
testImplementation 'junit:junit:4.+'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.navi.pulse
|
||||
|
||||
import android.content.Context
|
||||
import com.navi.pulse.event.PulseEventManager
|
||||
import com.navi.pulse.network.PulseRetrofitProvider
|
||||
|
||||
/**
|
||||
* A helper class that apps can interact with
|
||||
@@ -11,6 +12,7 @@ object PulseHelper {
|
||||
|
||||
fun init(sdkConfig: PulseSDKConfig.Configuration, context: Context) {
|
||||
applicationContext = context
|
||||
PulseRetrofitProvider.init(applicationContext)
|
||||
PulseSDKConfig.init(context, sdkConfig)
|
||||
PulseEventManager.startSyncEvents(context)
|
||||
}
|
||||
|
||||
@@ -5,10 +5,17 @@ import androidx.room.Room
|
||||
import com.navi.pulse.util.PulseConstants.EVENT_DB_NAME
|
||||
|
||||
object PulseDatabaseHelper {
|
||||
@Volatile
|
||||
private var INSTANCE: PulseDatabase? = null
|
||||
|
||||
fun getPulseDatabase(context: Context): PulseDatabase {
|
||||
return Room.databaseBuilder(
|
||||
context,
|
||||
PulseDatabase::class.java, EVENT_DB_NAME
|
||||
).build()
|
||||
return INSTANCE ?: synchronized(this) {
|
||||
val instance = Room.databaseBuilder(
|
||||
context,
|
||||
PulseDatabase::class.java, EVENT_DB_NAME
|
||||
).build()
|
||||
INSTANCE = instance
|
||||
instance
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,10 +105,7 @@ object PulseEventManager {
|
||||
} catch (e: Exception) {
|
||||
PulseLogger.log(LOG_TAG, "Error in Sending Data" + e.message)
|
||||
return false
|
||||
} finally {
|
||||
db.close()
|
||||
}
|
||||
|
||||
} else {
|
||||
PulseLogger.log(LOG_TAG, "No More Events to Send !")
|
||||
return false
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.navi.pulse.network
|
||||
|
||||
import android.content.Context
|
||||
import com.navi.pulse.BuildConfig
|
||||
import com.readystatesoftware.chuck.ChuckInterceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
@@ -10,14 +12,17 @@ import java.util.concurrent.TimeUnit
|
||||
object PulseRetrofitProvider {
|
||||
private const val BASE_URL_DEBUG = "https://dev-janus.np.navi-tech.in/"
|
||||
private const val BASE_URL_PROD = "https://janus.prod.navi-tech.in/"
|
||||
private val apiService: PulseRetrofitService
|
||||
private val okHttpClient: OkHttpClient
|
||||
private lateinit var apiService: PulseRetrofitService
|
||||
private lateinit var okHttpClient: OkHttpClient
|
||||
|
||||
init {
|
||||
fun init(context: Context) {
|
||||
okHttpClient = OkHttpClient.Builder()
|
||||
.connectTimeout(20, TimeUnit.SECONDS)
|
||||
.readTimeout(20, TimeUnit.SECONDS)
|
||||
.addInterceptor(loggingInterceptor())
|
||||
.addInterceptor(
|
||||
ChuckInterceptor(context)
|
||||
)
|
||||
.build()
|
||||
apiService =
|
||||
getRetrofit().create(PulseRetrofitService::class.java)
|
||||
|
||||
@@ -32,8 +32,6 @@ class AddEventTask(
|
||||
} catch (e: Exception) {
|
||||
PulseLogger.log(PulseConstants.LOG_TAG, "data insertion failed")
|
||||
false
|
||||
} finally {
|
||||
db.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user