This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override fun onCreate() { | |
| super<Application>.onCreate() | |
| Timber.plant(CrashlyticsLogTree(FirebaseCrashlytics.getInstance())) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| plugins { | |
| ... | |
| id 'com.google.firebase.crashlytics' | |
| } | |
| dependencies { | |
| ... | |
| implementation 'com.google.firebase:firebase-crashlytics-ktx' | |
| implementation "com.jakewharton.timber:timber:5.0.1" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| buildscript { | |
| repositories { | |
| google() | |
| } | |
| dependencies { | |
| classpath 'com.google.gms:google-services:4.3.13' | |
| classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1' | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private const val DATA_STORE_FILE_NAME = "emp_prefs.pb" | |
| class EmployeeInfo(private val context: Context) { | |
| private val Context.employeeProtoDataStore: DataStore<EmployeePreference> by dataStore( | |
| fileName = DATA_STORE_FILE_NAME, | |
| serializer = EmployeePreferencesSerializer | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Reading employee object from a proto data store | |
| val employeeInfo: Flow<EmployeePreference> = context.employeeProtoDataStore.data | |
| .map { | |
| it | |
| } | |
| //Reading employee object property empName from a proto data store | |
| val empName: Flow<String> = context.employeeProtoDataStore.data | |
| .map { | |
| it.empName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| suspend fun saveEmployeeInfo(eName: String, eDesignation: String) { | |
| context.employeeProtoDataStore.updateData { employeeData -> | |
| employeeData.toBuilder() | |
| .setEmpName(eName) | |
| .setEmpDesignation(eDesignation) | |
| .build() | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private val Context.employeeProtoDataStore: DataStore<EmployeePreference> by dataStore( | |
| fileName = DATA_STORE_FILE_NAME, | |
| serializer = EmployeePreferencesSerializer | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object EmployeePreferencesSerializer : Serializer<EmployeePreference> { | |
| override val defaultValue: EmployeePreference = EmployeePreference.getDefaultInstance() | |
| @Suppress("BlockingMethodInNonBlockingContext") | |
| override suspend fun readFrom(input: InputStream): EmployeePreference { | |
| try { | |
| return EmployeePreference.parseFrom(input) | |
| } catch (exception: InvalidProtocolBufferException) { | |
| throw CorruptionException("Cannot read proto.", exception) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| syntax = "proto3"; | |
| option java_package = "com.example.protodatastore"; | |
| option java_multiple_files = true; | |
| message EmployeePreference{ | |
| string emp_name = 1; | |
| string emp_designation = 2; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protobuf { | |
| protoc { | |
| artifact = "com.google.protobuf:protoc:3.19.4" | |
| } | |
| // Generates the java Protobuf-lite code for the Protobufs in this project. See | |
| // https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation | |
| // for more information. | |
| generateProtoTasks { | |
| all().each { task -> |