Skip to content

Commit 55282c5

Browse files
committed
Merge branch 'master' into feature-courses-viewmodel-orchestration-10508090116705126768
2 parents 46591dd + 678143a commit 55282c5

19 files changed

Lines changed: 395 additions & 176 deletions

app/build.gradle

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ android {
1212
applicationId "org.ole.planet.myplanet"
1313
minSdk = 26
1414
targetSdk = 36
15-
<<<<<<< perf-courses-repository-cleanup-11227507646865697827
16-
versionCode = 5315
17-
versionName = "0.53.15"
18-
=======
19-
versionCode = 5314
20-
versionName = "0.53.14"
21-
>>>>>>> master
15+
versionCode = 5326
16+
versionName = "0.53.26"
2217
ndkVersion = '26.3.11579264'
2318
vectorDrawables.useSupportLibrary = true
2419
}

app/src/main/java/org/ole/planet/myplanet/di/DatabaseModule.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import dagger.hilt.components.SingletonComponent
1111
import javax.inject.Singleton
1212
import kotlinx.coroutines.CoroutineDispatcher
1313
import kotlinx.coroutines.android.asCoroutineDispatcher
14+
import kotlinx.coroutines.asCoroutineDispatcher
1415
import org.ole.planet.myplanet.data.DatabaseService
1516
import org.ole.planet.myplanet.di.RealmDispatcher
1617
import org.ole.planet.myplanet.utils.DispatcherProvider
@@ -29,9 +30,10 @@ object DatabaseModule {
2930
@Singleton
3031
@RealmDispatcher
3132
fun provideRealmDispatcher(): CoroutineDispatcher {
32-
val handlerThread = HandlerThread("RealmQueryThread")
33-
handlerThread.start()
34-
return Handler(handlerThread.looper).asCoroutineDispatcher()
33+
// App-level shutdown hook ownership
34+
return java.util.concurrent.Executors.newSingleThreadExecutor { r ->
35+
Thread(r, "RealmQueryThread")
36+
}.asCoroutineDispatcher()
3537
}
3638

3739
// Realm initialization is handled in DatabaseService

app/src/main/java/org/ole/planet/myplanet/model/RealmNews.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ open class RealmNews : RealmObject() {
5151
var sharedBy: String? = null
5252
@Ignore
5353
var sortDate: Long = 0
54+
@Ignore
55+
var parsedViewIn: JsonArray? = null
56+
@Ignore
57+
var parsedConversations: List<RealmConversation>? = null
58+
@Ignore
59+
var parsedImageUrls: List<JsonObject>? = null
60+
@Ignore
61+
var rawViewIn: String? = null
62+
@Ignore
63+
var rawConversations: String? = null
64+
@Ignore
65+
var rawImageUrls: List<String>? = null
5466

5567
val imagesArray: JsonArray
5668
get() = if (images == null) JsonArray() else JsonUtils.gson.fromJson(images, JsonArray::class.java)

app/src/main/java/org/ole/planet/myplanet/repository/RatingsRepositoryImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class RatingsRepositoryImpl @Inject constructor(
2323
equalTo("type", type)
2424
}
2525
val aggregated = aggregateRatings(ratings, userId)
26-
val map = HashMap<String?, JsonObject>()
26+
val map = HashMap<String?, JsonObject>(Math.ceil(aggregated.size / 0.75).toInt())
2727
for ((item, aggregation) in aggregated) {
2828
map[item] = aggregation.toJson()
2929
}

app/src/main/java/org/ole/planet/myplanet/repository/ResourcesRepositoryImpl.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,7 @@ class ResourcesRepositoryImpl @Inject constructor(
329329

330330
override suspend fun markAllResourcesOffline(isOffline: Boolean) {
331331
executeTransaction { realm ->
332-
val libraries = realm.where(RealmMyLibrary::class.java).findAll()
333-
for (library in libraries) {
334-
library.resourceOffline = isOffline
335-
}
332+
realm.where(RealmMyLibrary::class.java).findAll().setValue("resourceOffline", isOffline)
336333
}
337334
}
338335

@@ -613,7 +610,7 @@ class ResourcesRepositoryImpl @Inject constructor(
613610

614611
override suspend fun getResourceRatingsBulk(ids: List<String>, userId: String?): Map<String?, JsonObject> {
615612
val allRatings = ratingsRepository.getResourceRatings(userId)
616-
val filteredRatings = HashMap<String?, JsonObject>()
613+
val filteredRatings = HashMap<String?, JsonObject>(Math.ceil(ids.size / 0.75).toInt())
617614
for (id in ids) {
618615
allRatings[id]?.let {
619616
filteredRatings[id] = it

app/src/main/java/org/ole/planet/myplanet/repository/TeamsRepository.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ interface TeamsRepository {
126126
suspend fun getAvailableResourcesToAdd(teamId: String): List<RealmMyLibrary>
127127
suspend fun getTeamVisitCount(userName: String?, teamId: String?): Long
128128

129-
fun insertTeamLog(realm: Realm, json: JsonObject)
130-
fun getLastVisit(realm: Realm, userName: String?, teamId: String?): Long?
129+
suspend fun insertTeamLog(json: JsonObject)
130+
suspend fun insertTeamLogs(logs: List<JsonObject>)
131+
suspend fun getLastVisit(userName: String?, teamId: String?): Long?
131132
fun serializeTeamActivities(log: RealmTeamLog, context: Context): JsonObject
132133
fun insertMyTeam(realm: io.realm.Realm, doc: com.google.gson.JsonObject)
133134
fun bulkInsertFromSync(realm: io.realm.Realm, jsonArray: com.google.gson.JsonArray)

app/src/main/java/org/ole/planet/myplanet/repository/TeamsRepositoryImpl.kt

Lines changed: 90 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import kotlinx.coroutines.flow.map
2222
import kotlinx.coroutines.withContext
2323
import org.ole.planet.myplanet.MainApplication
2424
import org.ole.planet.myplanet.data.DatabaseService
25-
import org.ole.planet.myplanet.data.api.ApiInterface
2625
import org.ole.planet.myplanet.di.AppPreferences
2726
import org.ole.planet.myplanet.di.RealmDispatcher
2827
import org.ole.planet.myplanet.model.CreateTeamRequest
@@ -53,7 +52,6 @@ class TeamsRepositoryImpl @Inject constructor(
5352
private val sharedPrefManager: org.ole.planet.myplanet.services.SharedPrefManager,
5453
private val serverUrlMapper: ServerUrlMapper,
5554
private val dispatcherProvider: DispatcherProvider,
56-
private val apiInterface: ApiInterface,
5755
private val userRepository: UserRepository,
5856
) : RealmRepository(databaseService, realmDispatcher), TeamsRepository {
5957
override suspend fun getTasksFlow(userId: String?): Flow<List<RealmTeamTask>> {
@@ -1305,31 +1303,58 @@ class TeamsRepositoryImpl @Inject constructor(
13051303
}
13061304
}
13071305

1308-
override fun insertTeamLog(realm: Realm, json: JsonObject) {
1309-
var tag = realm.where(RealmTeamLog::class.java)
1310-
.equalTo("_id", JsonUtils.getString("_id", json)).findFirst()
1311-
if (tag == null) {
1312-
tag = realm.createObject(RealmTeamLog::class.java, JsonUtils.getString("_id", json))
1306+
override suspend fun insertTeamLog(json: JsonObject) {
1307+
executeTransaction { realm ->
1308+
var tag = realm.where(RealmTeamLog::class.java)
1309+
.equalTo("_id", JsonUtils.getString("_id", json)).findFirst()
1310+
if (tag == null) {
1311+
tag = realm.createObject(RealmTeamLog::class.java, JsonUtils.getString("_id", json))
1312+
}
1313+
if (tag != null) {
1314+
tag._rev = JsonUtils.getString("_rev", json)
1315+
tag._id = JsonUtils.getString("_id", json)
1316+
tag.type = JsonUtils.getString("type", json)
1317+
tag.user = JsonUtils.getString("user", json)
1318+
tag.createdOn = JsonUtils.getString("createdOn", json)
1319+
tag.parentCode = JsonUtils.getString("parentCode", json)
1320+
tag.time = JsonUtils.getLong("time", json)
1321+
tag.teamId = JsonUtils.getString("teamId", json)
1322+
tag.teamType = JsonUtils.getString("teamType", json)
1323+
}
13131324
}
1314-
if (tag != null) {
1315-
tag._rev = JsonUtils.getString("_rev", json)
1316-
tag._id = JsonUtils.getString("_id", json)
1317-
tag.type = JsonUtils.getString("type", json)
1318-
tag.user = JsonUtils.getString("user", json)
1319-
tag.createdOn = JsonUtils.getString("createdOn", json)
1320-
tag.parentCode = JsonUtils.getString("parentCode", json)
1321-
tag.time = JsonUtils.getLong("time", json)
1322-
tag.teamId = JsonUtils.getString("teamId", json)
1323-
tag.teamType = JsonUtils.getString("teamType", json)
1325+
}
1326+
1327+
override suspend fun insertTeamLogs(logs: List<JsonObject>) {
1328+
executeTransaction { realm ->
1329+
for (json in logs) {
1330+
var tag = realm.where(RealmTeamLog::class.java)
1331+
.equalTo("_id", JsonUtils.getString("_id", json)).findFirst()
1332+
if (tag == null) {
1333+
tag = realm.createObject(RealmTeamLog::class.java, JsonUtils.getString("_id", json))
1334+
}
1335+
if (tag != null) {
1336+
tag._rev = JsonUtils.getString("_rev", json)
1337+
tag._id = JsonUtils.getString("_id", json)
1338+
tag.type = JsonUtils.getString("type", json)
1339+
tag.user = JsonUtils.getString("user", json)
1340+
tag.createdOn = JsonUtils.getString("createdOn", json)
1341+
tag.parentCode = JsonUtils.getString("parentCode", json)
1342+
tag.time = JsonUtils.getLong("time", json)
1343+
tag.teamId = JsonUtils.getString("teamId", json)
1344+
tag.teamType = JsonUtils.getString("teamType", json)
1345+
}
1346+
}
13241347
}
13251348
}
13261349

1327-
override fun getLastVisit(realm: Realm, userName: String?, teamId: String?): Long? {
1328-
return realm.where(RealmTeamLog::class.java)
1329-
.equalTo("type", "teamVisit")
1330-
.equalTo("user", userName)
1331-
.equalTo("teamId", teamId)
1332-
.max("time")?.toLong()
1350+
override suspend fun getLastVisit(userName: String?, teamId: String?): Long? {
1351+
return withRealm { realm ->
1352+
realm.where(RealmTeamLog::class.java)
1353+
.equalTo("type", "teamVisit")
1354+
.equalTo("user", userName)
1355+
.equalTo("teamId", teamId)
1356+
.max("time")?.toLong()
1357+
}
13331358
}
13341359

13351360
override fun serializeTeamActivities(log: RealmTeamLog, context: Context): JsonObject {
@@ -1359,54 +1384,54 @@ class TeamsRepositoryImpl @Inject constructor(
13591384
val concatenatedLink = "$baseUrl/$link"
13601385
concatenatedLinks.add(concatenatedLink)
13611386
}
1362-
org.ole.planet.myplanet.utils.DownloadUtils.openDownloadService(org.ole.planet.myplanet.MainApplication.context, ArrayList(concatenatedLinks), true)
1387+
org.ole.planet.myplanet.utils.DownloadUtils.openDownloadService(MainApplication.context, ArrayList(concatenatedLinks), true)
13631388
}
13641389

1365-
override fun insertMyTeam(realm: io.realm.Realm, doc: com.google.gson.JsonObject) {
1366-
val status = org.ole.planet.myplanet.utils.JsonUtils.getString("status", doc)
1390+
override fun insertMyTeam(realm: Realm, doc: JsonObject) {
1391+
val status = JsonUtils.getString("status", doc)
13671392
if (status == "archived") {
13681393
return
13691394
}
13701395

1371-
val teamId = org.ole.planet.myplanet.utils.JsonUtils.getString("_id", doc)
1372-
val docType = org.ole.planet.myplanet.utils.JsonUtils.getString("docType", doc)
1373-
val userId = org.ole.planet.myplanet.utils.JsonUtils.getString("userId", doc)
1374-
val teamIdField = org.ole.planet.myplanet.utils.JsonUtils.getString("teamId", doc)
1396+
val teamId = JsonUtils.getString("_id", doc)
1397+
val docType = JsonUtils.getString("docType", doc)
1398+
val userId = JsonUtils.getString("userId", doc)
1399+
val teamIdField = JsonUtils.getString("teamId", doc)
13751400

13761401
if (docType == "membership" && userId.isNotBlank() && teamIdField.isNotBlank()) {
13771402
// Server accepted the request (possibly as a new doc); remove any stale request records
1378-
realm.where(org.ole.planet.myplanet.model.RealmMyTeam::class.java)
1403+
realm.where(RealmMyTeam::class.java)
13791404
.equalTo("teamId", teamIdField)
13801405
.equalTo("userId", userId)
13811406
.equalTo("docType", "request")
13821407
.findAll()
13831408
.deleteAllFromRealm()
13841409
} else if (docType == "request" && userId.isNotBlank() && teamIdField.isNotBlank()) {
13851410
// Skip stale request record if the user is already a member
1386-
val alreadyMember = realm.where(org.ole.planet.myplanet.model.RealmMyTeam::class.java)
1411+
val alreadyMember = realm.where(RealmMyTeam::class.java)
13871412
.equalTo("teamId", teamIdField)
13881413
.equalTo("userId", userId)
13891414
.equalTo("docType", "membership")
13901415
.count() > 0
13911416
if (alreadyMember) return
13921417
}
13931418

1394-
var myTeams = realm.where(org.ole.planet.myplanet.model.RealmMyTeam::class.java).equalTo("_id", teamId).findFirst()
1419+
var myTeams = realm.where(RealmMyTeam::class.java).equalTo("_id", teamId).findFirst()
13951420
if (myTeams == null) {
1396-
myTeams = realm.createObject(org.ole.planet.myplanet.model.RealmMyTeam::class.java, teamId)
1421+
myTeams = realm.createObject(RealmMyTeam::class.java, teamId)
13971422
}
13981423
myTeams?.let {
1399-
org.ole.planet.myplanet.model.RealmMyTeam.populateTeamFields(doc, it, true)
1424+
RealmMyTeam.populateTeamFields(doc, it, true)
14001425
processDescription(it.description)
14011426
}
14021427
}
14031428

1404-
override fun bulkInsertFromSync(realm: io.realm.Realm, jsonArray: com.google.gson.JsonArray) {
1405-
val documentList = ArrayList<com.google.gson.JsonObject>(jsonArray.size())
1429+
override fun bulkInsertFromSync(realm: Realm, jsonArray: com.google.gson.JsonArray) {
1430+
val documentList = ArrayList<JsonObject>(jsonArray.size())
14061431
for (j in jsonArray) {
14071432
var jsonDoc = j.asJsonObject
1408-
jsonDoc = org.ole.planet.myplanet.utils.JsonUtils.getJsonObject("doc", jsonDoc)
1409-
val id = org.ole.planet.myplanet.utils.JsonUtils.getString("_id", jsonDoc)
1433+
jsonDoc = JsonUtils.getJsonObject("doc", jsonDoc)
1434+
val id = JsonUtils.getString("_id", jsonDoc)
14101435
if (!id.startsWith("_design")) {
14111436
documentList.add(jsonDoc)
14121437
}
@@ -1415,32 +1440,47 @@ class TeamsRepositoryImpl @Inject constructor(
14151440
insertMyTeam(realm, jsonDoc)
14161441
}
14171442
}
1418-
override fun bulkInsertTasksFromSync(realm: io.realm.Realm, jsonArray: com.google.gson.JsonArray) {
1419-
val documentList = ArrayList<com.google.gson.JsonObject>(jsonArray.size())
1443+
override fun bulkInsertTasksFromSync(realm: Realm, jsonArray: com.google.gson.JsonArray) {
1444+
val documentList = ArrayList<JsonObject>(jsonArray.size())
14201445
for (j in jsonArray) {
14211446
var jsonDoc = j.asJsonObject
1422-
jsonDoc = org.ole.planet.myplanet.utils.JsonUtils.getJsonObject("doc", jsonDoc)
1423-
val id = org.ole.planet.myplanet.utils.JsonUtils.getString("_id", jsonDoc)
1447+
jsonDoc = JsonUtils.getJsonObject("doc", jsonDoc)
1448+
val id = JsonUtils.getString("_id", jsonDoc)
14241449
if (!id.startsWith("_design")) {
14251450
documentList.add(jsonDoc)
14261451
}
14271452
}
14281453
documentList.forEach { jsonDoc ->
1429-
org.ole.planet.myplanet.model.RealmTeamTask.insert(realm, jsonDoc)
1454+
RealmTeamTask.insert(realm, jsonDoc)
14301455
}
14311456
}
1432-
override fun bulkInsertTeamActivitiesFromSync(realm: io.realm.Realm, jsonArray: com.google.gson.JsonArray) {
1433-
val documentList = ArrayList<com.google.gson.JsonObject>(jsonArray.size())
1457+
override fun bulkInsertTeamActivitiesFromSync(realm: Realm, jsonArray: com.google.gson.JsonArray) {
1458+
val documentList = ArrayList<JsonObject>(jsonArray.size())
14341459
for (j in jsonArray) {
14351460
var jsonDoc = j.asJsonObject
1436-
jsonDoc = org.ole.planet.myplanet.utils.JsonUtils.getJsonObject("doc", jsonDoc)
1437-
val id = org.ole.planet.myplanet.utils.JsonUtils.getString("_id", jsonDoc)
1461+
jsonDoc = JsonUtils.getJsonObject("doc", jsonDoc)
1462+
val id = JsonUtils.getString("_id", jsonDoc)
14381463
if (!id.startsWith("_design")) {
14391464
documentList.add(jsonDoc)
14401465
}
14411466
}
1442-
documentList.forEach { jsonDoc ->
1443-
insertTeamLog(realm, jsonDoc)
1467+
for (json in documentList) {
1468+
var tag = realm.where(RealmTeamLog::class.java)
1469+
.equalTo("_id", JsonUtils.getString("_id", json)).findFirst()
1470+
if (tag == null) {
1471+
tag = realm.createObject(RealmTeamLog::class.java, JsonUtils.getString("_id", json))
1472+
}
1473+
if (tag != null) {
1474+
tag._rev = JsonUtils.getString("_rev", json)
1475+
tag._id = JsonUtils.getString("_id", json)
1476+
tag.type = JsonUtils.getString("type", json)
1477+
tag.user = JsonUtils.getString("user", json)
1478+
tag.createdOn = JsonUtils.getString("createdOn", json)
1479+
tag.parentCode = JsonUtils.getString("parentCode", json)
1480+
tag.time = JsonUtils.getLong("time", json)
1481+
tag.teamId = JsonUtils.getString("teamId", json)
1482+
tag.teamType = JsonUtils.getString("teamType", json)
1483+
}
14441484
}
14451485
}
14461486
}

app/src/main/java/org/ole/planet/myplanet/services/FreeSpaceWorker.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.ole.planet.myplanet.services
22

33
import android.content.Context
4+
import android.util.Log
45
import androidx.hilt.work.HiltWorker
56
import androidx.work.CoroutineWorker
67
import androidx.work.WorkerParameters
@@ -39,7 +40,7 @@ class FreeSpaceWorker @AssistedInject constructor(
3940

4041
Result.success(workDataOf("deletedFiles" to deletedFiles, "freedBytes" to freedBytes))
4142
} catch (e: Exception) {
42-
e.printStackTrace()
43+
Log.e(TAG, "Error in FreeSpaceWorker", e)
4344
Result.failure()
4445
}
4546
}
@@ -72,4 +73,8 @@ class FreeSpaceWorker @AssistedInject constructor(
7273
}
7374
}
7475
}
76+
77+
companion object {
78+
private const val TAG = "FreeSpaceWorker"
79+
}
7580
}

app/src/main/java/org/ole/planet/myplanet/services/sync/TransactionSyncManager.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,25 @@ class TransactionSyncManager @Inject constructor(
260260
insertDuration,
261261
arr.size()
262262
)
263+
} else if (table == "team_activities") {
264+
val insertStartTime = System.currentTimeMillis()
265+
val docs = mutableListOf<JsonObject>()
266+
for (j in arr) {
267+
var jsonDoc = j.asJsonObject
268+
jsonDoc = getJsonObject("doc", jsonDoc)
269+
val id = getString("_id", jsonDoc)
270+
if (!id.startsWith("_design")) {
271+
docs.add(jsonDoc)
272+
}
273+
}
274+
teamsRepository.get().insertTeamLogs(docs)
275+
val insertDuration = System.currentTimeMillis() - insertStartTime
276+
org.ole.planet.myplanet.utils.SyncTimeLogger.logRealmOperation(
277+
"insert_batch",
278+
table,
279+
insertDuration,
280+
arr.size()
281+
)
263282
} else if (table == "login_activities") {
264283
val insertStartTime = System.currentTimeMillis()
265284
val docs = mutableListOf<JsonObject>()

0 commit comments

Comments
 (0)