-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathSampleApp.kt
More file actions
104 lines (94 loc) · 3.54 KB
/
Copy pathSampleApp.kt
File metadata and controls
104 lines (94 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.sampleapp
import android.app.Application
import android.os.StrictMode
import android.os.StrictMode.ThreadPolicy
import android.os.StrictMode.VmPolicy
import android.util.Log
import com.pluto.Pluto
import com.pluto.plugins.datastore.pref.PlutoDatastoreWatcher
import com.pluto.plugins.exceptions.PlutoExceptions
import com.pluto.plugins.exceptions.PlutoExceptionsPlugin
import com.pluto.plugins.layoutinspector.PlutoLayoutInspectorPlugin
import com.pluto.plugins.logger.PlutoLoggerPlugin
import com.pluto.plugins.logger.PlutoTimberTree
import com.pluto.plugins.network.PlutoNetworkPlugin
import com.pluto.plugins.rooms.db.PlutoRoomsDBWatcher
import com.sampleapp.functions.datastore.DemoDatastorePrefFragment.Companion.APP_STATE_PREF_NAME
import com.sampleapp.functions.datastore.DemoDatastorePrefFragment.Companion.USER_STATE_PREF_NAME
import com.sampleapp.functions.datastore.appStateDatastore
import com.sampleapp.functions.datastore.userStateDatastore
import com.sampleapp.functions.roomsdatabase.db.SampleDatabase
import com.sampleapp.functions.roomsdatabase.db2.Sample2Database
import com.sampleapp.pluto.DataSourcePluginGroup
import kotlin.system.exitProcess
import timber.log.Timber
class SampleApp : Application() {
override fun onCreate() {
initializeStrictMode()
super.onCreate()
Pluto.Installer(this)
.addPlugin(PlutoExceptionsPlugin())
// .addPlugin(PlutoDatastorePreferencesPlugin())
.addPlugin(PlutoNetworkPlugin())
.addPlugin(PlutoLoggerPlugin())
// .addPlugin(PlutoSharePreferencesPlugin())
// .addPlugin(PlutoRoomsDatabasePlugin())
.addPlugin(PlutoLayoutInspectorPlugin())
.addPluginGroup(DataSourcePluginGroup())
.install()
Pluto.showNotch(true)
plantPlutoTimber()
setExceptionListener()
watchRoomsDatabase()
watchDatastorePreferences()
}
private fun initializeStrictMode() {
StrictMode.setThreadPolicy(
ThreadPolicy.Builder()
.permitDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build()
)
StrictMode.setVmPolicy(
VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.build()
)
}
/**
* Datastore Preferences handler
*/
private fun watchDatastorePreferences() {
PlutoDatastoreWatcher.watch(APP_STATE_PREF_NAME, appStateDatastore)
PlutoDatastoreWatcher.watch(USER_STATE_PREF_NAME, userStateDatastore)
}
/**
* Rooms database handler
*/
private fun watchRoomsDatabase() {
PlutoRoomsDBWatcher.watch(SampleDatabase.DB_NAME, SampleDatabase::class.java)
PlutoRoomsDBWatcher.watch(Sample2Database.DB_NAME, Sample2Database::class.java)
}
/**
* Logger Timber handler
*/
private fun plantPlutoTimber() {
Timber.plant(PlutoTimberTree())
}
/**
* Exception handler
*/
private fun setExceptionListener() {
PlutoExceptions.setExceptionHandler { thread, throwable ->
Log.e("exception_demo", "uncaught exception handled on thread: " + thread.name, throwable)
exitProcess(0)
}
PlutoExceptions.setANRHandler { thread, exception ->
Log.e("anr_demo", "unhandled ANR handled on thread: " + thread.name, exception)
}
}
}