Skip to content

Commit

Permalink
migrate transaction syncManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 committed Dec 18, 2024
1 parent 7063068 commit 3f94d5f
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 171 deletions.
19 changes: 11 additions & 8 deletions app/src/main/java/org/ole/planet/myplanet/model/RealmFeedback.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.ole.planet.myplanet.model

import com.google.gson.*
import com.opencsv.CSVWriter
import io.realm.kotlin.Realm
import io.realm.kotlin.ext.query
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.PrimaryKey
import org.ole.planet.myplanet.MainApplication
import java.io.File
import java.io.FileWriter
import java.io.IOException
Expand Down Expand Up @@ -145,20 +147,21 @@ class RealmFeedback : RealmObject {
try {
val file = File(filePath)
file.parentFile?.mkdirs()
val writer = FileWriter(file)
writer.write("feedbackId,title,source,status,priority,owner,openTime,type,url,parentCode,state,item,messages\n")
data.forEach { row ->
writer.write(row.joinToString(","))
writer.write("\n")
CSVWriter(FileWriter(file)).use { writer ->
writer.writeNext(arrayOf(
"feedbackId","title","source","status","priority","owner","openTime","type","url","parentCode","state","item","messages"
))
data.forEach { row ->
writer.writeNext(row)
}
}
writer.close()
} catch (e: IOException) {
e.printStackTrace()
}
}

fun feedbackWriteCsv(filePath: String) {
writeCsv(filePath, feedbacksDataList)
fun feedbackWriteCsv() {
writeCsv("${MainApplication.context.getExternalFilesDir(null)}/ole/feedback.csv", feedbacksDataList)
}
}
}
11 changes: 6 additions & 5 deletions app/src/main/java/org/ole/planet/myplanet/model/RealmRating.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.realm.kotlin.Realm
import io.realm.kotlin.ext.query
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.PrimaryKey
import org.ole.planet.myplanet.MainApplication
import java.io.File
import java.io.FileWriter
import java.io.IOException
Expand All @@ -31,7 +32,7 @@ class RealmRating : RealmObject {
companion object {
private val ratingDataList: MutableList<Array<String>> = mutableListOf()

suspend fun getRatings(realm: Realm, type: String?, userId: String?): Map<String?, JsonObject> {
fun getRatings(realm: Realm, type: String?, userId: String?): Map<String?, JsonObject> {
val results = realm.query<RealmRating>("type == $0", type).find()
val map = mutableMapOf<String?, JsonObject>()

Expand All @@ -43,7 +44,7 @@ class RealmRating : RealmObject {
return map
}

suspend fun getRatingsById(realm: Realm, type: String?, id: String?, userId: String?): JsonObject? {
fun getRatingsById(realm: Realm, type: String?, id: String?, userId: String?): JsonObject? {
val results = realm.query<RealmRating>("type == $0 && itemId == $1", type, id).find()
if (results.isEmpty()) return null

Expand Down Expand Up @@ -77,7 +78,7 @@ class RealmRating : RealmObject {
}


suspend fun insert(realm: Realm, act: JsonObject) {
fun insert(realm: Realm, act: JsonObject) {
realm.writeBlocking {
val rating = query<RealmRating>("id == $0", act.get("_id").asString).first().find()
?: RealmRating().apply {
Expand Down Expand Up @@ -139,8 +140,8 @@ class RealmRating : RealmObject {
}
}

fun ratingWriteCsv(filePath: String) {
writeCsv(filePath, ratingDataList)
fun ratingWriteCsv() {
writeCsv("${MainApplication.context.getExternalFilesDir(null)}/ole/rating.csv", ratingDataList)
}
}
}
Loading

0 comments on commit 3f94d5f

Please sign in to comment.