@@ -25,6 +25,7 @@ import org.ole.planet.myplanet.di.DatabaseServiceEntryPoint
2525import org.ole.planet.myplanet.di.RepositoryEntryPoint
2626import org.ole.planet.myplanet.model.MyPlanet
2727import org.ole.planet.myplanet.model.RealmCommunity
28+ import org.ole.planet.myplanet.repository.CommunityRepository
2829import org.ole.planet.myplanet.repository.UserRepository
2930import org.ole.planet.myplanet.services.ConfigurationManager
3031import org.ole.planet.myplanet.services.UploadToShelfService
@@ -46,6 +47,7 @@ class DataService constructor(
4647 @param:ApplicationScope private val serviceScope : CoroutineScope ,
4748 private val userRepository : UserRepository ,
4849 private val uploadToShelfService : UploadToShelfService ,
50+ private val communityRepository : CommunityRepository ,
4951) {
5052 constructor (context: Context ) : this (
5153 context,
@@ -69,6 +71,10 @@ class DataService constructor(
6971 context.applicationContext,
7072 AutoSyncEntryPoint ::class .java
7173 ).uploadToShelfService(),
74+ EntryPointAccessors .fromApplication(
75+ context.applicationContext,
76+ RepositoryEntryPoint ::class .java
77+ ).communityRepository(),
7278 )
7379
7480 private val preferences: SharedPreferences = context.getSharedPreferences(Constants .PREFS_NAME , Context .MODE_PRIVATE )
@@ -204,26 +210,7 @@ class DataService constructor(
204210 println (" Realm transaction started" )
205211
206212 val transactionResult = runCatching {
207- withContext(Dispatchers .IO ) {
208- databaseService.withRealm { backgroundRealm ->
209- backgroundRealm.executeTransaction { realm1 ->
210- realm1.delete(RealmCommunity ::class .java)
211- for (j in arr) {
212- var jsonDoc = j.asJsonObject
213- jsonDoc = JsonUtils .getJsonObject(" doc" , jsonDoc)
214- val id = JsonUtils .getString(" _id" , jsonDoc)
215- val community = realm1.createObject(RealmCommunity ::class .java, id)
216- if (JsonUtils .getString(" name" , jsonDoc) == " learning" ) {
217- community.weight = 0
218- }
219- community.localDomain = JsonUtils .getString(" localDomain" , jsonDoc)
220- community.name = JsonUtils .getString(" name" , jsonDoc)
221- community.parentDomain = JsonUtils .getString(" parentDomain" , jsonDoc)
222- community.registrationRequest = JsonUtils .getString(" registrationRequest" , jsonDoc)
223- }
224- }
225- }
226- }
213+ communityRepository.replaceAll(arr)
227214 }
228215
229216 val endTime = System .currentTimeMillis()
0 commit comments