diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 682f1682..d16d8cd9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -15,8 +15,6 @@ android { targetSdk = 34 versionCode = 48 versionName = "0.7.1" - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } compileOptions { @@ -160,6 +158,8 @@ dependencies { // https://github.com/requery/sqlite-android/releases // TODO remove bundled SQLite when Android bumps its deps // > The JSON functions and operators are built into SQLite by default, as of SQLite version 3.38.0 (2022-02-22). + // API 33 -> 3.32 + // API 34 -> 3.39 (~45% of our install base) // https://www.sqlite.org/json1.html implementation("com.github.requery:sqlite-android:3.45.0") @@ -174,23 +174,10 @@ dependencies { // https://developer.android.com/jetpack/androidx/releases/work val workVer = "2.9.0" implementation("androidx.work:work-runtime-ktx:$workVer") - androidTestImplementation("androidx.work:work-testing:$workVer") // Common test dependencies // https://junit.org/junit4/ val junitVer = "4.13.2" testImplementation("junit:junit:$junitVer") - androidTestImplementation("junit:junit:$junitVer") testImplementation("org.json:json:20231013") - - // Common instrumented test dependencies - // https://developer.android.com/jetpack/androidx/releases/test - androidTestImplementation("androidx.test:core-ktx:1.5.0") - androidTestImplementation("androidx.test.ext:junit-ktx:1.1.5") - androidTestImplementation("androidx.test:runner:1.5.2") - androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") - - // TODO remove when fixed upstream - // https://github.com/android/android-test/issues/1589 - debugImplementation("androidx.test:monitor:1.6.1") } \ No newline at end of file diff --git a/app/src/androidTest/kotlin/activity/ActivityTest.kt b/app/src/androidTest/kotlin/activity/ActivityTest.kt deleted file mode 100644 index 68bf38d7..00000000 --- a/app/src/androidTest/kotlin/activity/ActivityTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package activity - -import androidx.test.core.app.launchActivity -import androidx.test.espresso.Espresso -import androidx.test.espresso.assertion.ViewAssertions.* -import androidx.test.espresso.matcher.ViewMatchers.* -import junit.framework.TestCase.assertFalse -import org.btcmap.R -import org.hamcrest.Matchers.allOf -import org.junit.Test - -class ActivityTest { - - @Test - fun launch() { - launchActivity().use { scenario -> - Espresso - .onView(allOf(withId(R.id.nav_host_fragment), withParent(withId(-1)))) - .check(matches(isDisplayed())) - - scenario.onActivity { - assertFalse(it.window.decorView.fitsSystemWindows) - } - } - } -} \ No newline at end of file diff --git a/app/src/androidTest/kotlin/app/AppModuleTest.kt b/app/src/androidTest/kotlin/app/AppModuleTest.kt deleted file mode 100644 index 698d202e..00000000 --- a/app/src/androidTest/kotlin/app/AppModuleTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package app - -import androidx.test.platform.app.InstrumentationRegistry -import area.AreaModel -import org.junit.Test -import org.koin.android.ext.android.get - -class AppModuleTest { - - @Test - fun dependencies() { - val app = - InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as App - app.get() - } -} \ No newline at end of file diff --git a/app/src/androidTest/kotlin/app/AppTest.kt b/app/src/androidTest/kotlin/app/AppTest.kt deleted file mode 100644 index 29384d44..00000000 --- a/app/src/androidTest/kotlin/app/AppTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package app - -import androidx.test.platform.app.InstrumentationRegistry -import coil.decode.SvgDecoder -import coil.imageLoader -import org.junit.Test - -class AppTest { - - @Test - fun imageLoader() { - val app = - InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as App - val loader = app.imageLoader - assert(loader.components.decoderFactories.contains(SvgDecoder.Factory())) - } -} \ No newline at end of file diff --git a/app/src/androidTest/kotlin/area/AreaFragmentTest.kt b/app/src/androidTest/kotlin/area/AreaFragmentTest.kt deleted file mode 100644 index 10fe1ce4..00000000 --- a/app/src/androidTest/kotlin/area/AreaFragmentTest.kt +++ /dev/null @@ -1,93 +0,0 @@ -//package area -// -//import androidx.core.os.bundleOf -//import androidx.fragment.app.testing.launchFragmentInContainer -//import androidx.test.espresso.Espresso.onView -//import androidx.test.espresso.assertion.ViewAssertions.matches -//import androidx.test.espresso.matcher.ViewMatchers.* -//import androidx.test.platform.app.InstrumentationRegistry -//import app.App -//import kotlinx.coroutines.runBlocking -//import kotlinx.serialization.json.Json -//import org.btcmap.R -//import org.junit.Test -//import org.koin.android.ext.android.get -//import java.time.ZonedDateTime -// -//class AreaFragmentTest { -// -// @Test -// fun launch() { -// val app = -// InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as App -// val areaQueries = app.get() -// -// val area = Area( -// id = "test", -// tags = AreaTags( -// mapOf( -// "geo_json" to Json.Default.parseToJsonElement( -// """ -// { -// "type": "FeatureCollection", -// "features": [ -// { -// "type": "Feature", -// "properties": {}, -// "geometry": { -// "coordinates": [ -// [ -// [ -// 22.13883023642984, -// 3.2294073255228852 -// ], -// [ -// 22.17600937988118, -// 3.284691070754846 -// ], -// [ -// 22.069218223160163, -// 3.305487499546132 -// ], -// [ -// 21.994596254388597, -// 3.2986431532554406 -// ], -// [ -// 22.011471893969883, -// 3.224405313608429 -// ], -// [ -// 22.13883023642984, -// 3.2294073255228852 -// ] -// ] -// ], -// "type": "Polygon" -// } -// } -// ] -// } -// """.trimIndent() -// ) -// ) -// ), -// createdAt = ZonedDateTime.now(), -// updatedAt = ZonedDateTime.now(), -// deletedAt = null, -// ) -// -// runBlocking { -// areaQueries.insertOrReplace(listOf(area)) -// } -// -// launchFragmentInContainer( -// themeResId = com.google.android.material.R.style.Theme_Material3_DynamicColors_DayNight, -// fragmentArgs = bundleOf(Pair("area_id", area.id)), -// ).use { -// onView(withId(R.id.toolbar)).check(matches(isDisplayed())) -// onView(withId(R.id.progress)).check(matches(isEnabled())) -// onView(withId(R.id.list)).check(matches(isEnabled())) -// } -// } -//} \ No newline at end of file diff --git a/app/src/androidTest/kotlin/conf/ConfQueriesTest.kt b/app/src/androidTest/kotlin/conf/ConfQueriesTest.kt deleted file mode 100644 index 976f0a16..00000000 --- a/app/src/androidTest/kotlin/conf/ConfQueriesTest.kt +++ /dev/null @@ -1,30 +0,0 @@ -package conf - -import db.inMemoryDatabase -import kotlinx.coroutines.runBlocking -import org.junit.Assert.assertEquals -import org.junit.Before -import org.junit.Test - -class ConfQueriesTest { - - lateinit var queries: ConfQueries - - @Before - fun beforeEach() { - queries = ConfQueries(inMemoryDatabase()) - } - - @Test - fun insertOrReplace() = runBlocking { - queries.insertOrReplace(ConfRepo.DEFAULT_CONF) - assertEquals(ConfRepo.DEFAULT_CONF, queries.select()) - } - - @Test - fun select() = runBlocking { - assertEquals(null, queries.select()) - queries.insertOrReplace(ConfRepo.DEFAULT_CONF) - assertEquals(ConfRepo.DEFAULT_CONF, queries.select()) - } -} \ No newline at end of file diff --git a/app/src/androidTest/kotlin/conf/ConfRepoTest.kt b/app/src/androidTest/kotlin/conf/ConfRepoTest.kt deleted file mode 100644 index 3ee0cd58..00000000 --- a/app/src/androidTest/kotlin/conf/ConfRepoTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package conf - -import db.inMemoryDatabase -import org.junit.Assert.assertEquals -import org.junit.Test -import java.time.ZonedDateTime - -class ConfRepoTest { - - @Test - fun getConf() { - val repo = ConfRepo(ConfQueries(inMemoryDatabase())) - assertEquals(ConfRepo.DEFAULT_CONF, repo.conf.value) - val newConf = repo.conf.value.copy(lastSyncDate = ZonedDateTime.now()) - repo.update { newConf } - assertEquals(newConf, repo.conf.value) - } - - @Test - fun update() { - val repo = ConfRepo(ConfQueries(inMemoryDatabase())) - val lastSyncDate = ZonedDateTime.now() - repo.update { it.copy(lastSyncDate = lastSyncDate) } - assertEquals(lastSyncDate, repo.conf.value.lastSyncDate) - } -} \ No newline at end of file diff --git a/app/src/androidTest/kotlin/donation/DonationFragmentTest.kt b/app/src/androidTest/kotlin/donation/DonationFragmentTest.kt deleted file mode 100644 index 6d593264..00000000 --- a/app/src/androidTest/kotlin/donation/DonationFragmentTest.kt +++ /dev/null @@ -1,51 +0,0 @@ -package donation - -import android.content.ClipboardManager -import android.content.Context -import androidx.fragment.app.testing.launchFragmentInContainer -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.matcher.ViewMatchers.isClickable -import androidx.test.espresso.matcher.ViewMatchers.isDisplayed -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.platform.app.InstrumentationRegistry -import org.btcmap.R -import org.junit.Assert.assertEquals -import org.junit.Test - -class DonationFragmentTest { - - @Test - fun launch() { - launchFragmentInContainer( - themeResId = com.google.android.material.R.style.Theme_Material3_DynamicColors_DayNight, - ).use { - onView(withId(R.id.toolbar)).check(matches(isDisplayed())) - - onView(withId(R.id.qr)).check(matches(isDisplayed())) - onView(withId(R.id.copy)).check(matches(isDisplayed())) - onView(withId(R.id.copy)).check(matches(isClickable())) - - onView(withId(R.id.copy)).apply { - perform(click()) - val context = InstrumentationRegistry.getInstrumentation().targetContext - val clipManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - val clipboardText = clipManager.primaryClip!!.getItemAt(clipManager.primaryClip!!.itemCount - 1).text - assertEquals(context.getString(R.string.donation_address_onchain), clipboardText) - } - - onView(withId(R.id.lnQr)).check(matches(isDisplayed())) - onView(withId(R.id.lnCopy)).check(matches(isDisplayed())) - onView(withId(R.id.lnCopy)).check(matches(isClickable())) - - onView(withId(R.id.lnCopy)).apply { - perform(click()) - val context = InstrumentationRegistry.getInstrumentation().targetContext - val clipManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - val clipboardText = clipManager.primaryClip!!.getItemAt(clipManager.primaryClip!!.itemCount - 1).text - assertEquals(context.getString(R.string.donation_address_lightning), clipboardText) - } - } - } -} \ No newline at end of file diff --git a/app/src/androidTest/kotlin/element/ElementFragmentTest.kt b/app/src/androidTest/kotlin/element/ElementFragmentTest.kt deleted file mode 100644 index 194e7bf1..00000000 --- a/app/src/androidTest/kotlin/element/ElementFragmentTest.kt +++ /dev/null @@ -1,47 +0,0 @@ -//package element -// -//import androidx.fragment.app.testing.launchFragmentInContainer -//import androidx.test.espresso.Espresso.onView -//import androidx.test.espresso.assertion.ViewAssertions.matches -//import androidx.test.espresso.matcher.ViewMatchers.isDisplayed -//import androidx.test.espresso.matcher.ViewMatchers.withId -//import kotlinx.serialization.json.JsonObject -//import kotlinx.serialization.json.JsonPrimitive -//import org.btcmap.R -//import org.hamcrest.Matchers.not -//import org.junit.Test -//import java.time.ZoneOffset -//import java.time.ZonedDateTime -//import kotlin.random.Random -// -//class ElementFragmentTest { -// -// @Test -// fun launch() { -// launchFragmentInContainer( -// themeResId = com.google.android.material.R.style.Theme_Material3_DynamicColors_DayNight, -// ).use { scenario -> -// val tags = mutableMapOf() -// -// val element = Element( -// id = "${arrayOf("node", "way", "relation").random()}:${Random.nextLong()}", -// lat = Random.nextDouble(-90.0, 90.0), -// lon = Random.nextDouble(-180.0, 180.0), -// osmJson = JsonObject(mapOf("tags" to JsonObject(tags))), -// tags = JsonObject(emptyMap()), -// createdAt = ZonedDateTime.now(ZoneOffset.UTC) -// .minusMinutes(Random.nextLong(60 * 24 * 30)), -// updatedAt = ZonedDateTime.now(ZoneOffset.UTC) -// .minusMinutes(Random.nextLong(60 * 24 * 30)), -// deletedAt = null, -// ) -// -// scenario.onFragment { it.setElement(element) } -// onView(withId(R.id.address)).check(matches(not(isDisplayed()))) -// -// tags["addr:housenumber"] = JsonPrimitive("1") -// scenario.onFragment { it.setElement(element) } -// onView(withId(R.id.address)).check(matches(isDisplayed())) -// } -// } -//} \ No newline at end of file diff --git a/app/src/androidTest/kotlin/element/ElementQueriesTest.kt b/app/src/androidTest/kotlin/element/ElementQueriesTest.kt deleted file mode 100644 index e627e1ed..00000000 --- a/app/src/androidTest/kotlin/element/ElementQueriesTest.kt +++ /dev/null @@ -1,126 +0,0 @@ -//package element -// -//import db.inMemoryDatabase -//import kotlinx.coroutines.runBlocking -//import kotlinx.serialization.decodeFromString -//import kotlinx.serialization.json.Json -//import kotlinx.serialization.json.JsonObject -//import kotlinx.serialization.json.JsonPrimitive -//import org.junit.Assert.assertEquals -//import org.junit.Before -//import org.junit.Test -//import org.osmdroid.util.BoundingBox -//import org.osmdroid.util.GeoPoint -//import java.lang.Double.max -//import java.lang.Double.min -//import java.time.ZoneOffset -//import java.time.ZonedDateTime -//import kotlin.random.Random -// -//class ElementQueriesTest { -// -// private lateinit var queries: ElementQueries -// -// @Before -// fun beforeEach() { -// queries = ElementQueries(inMemoryDatabase()) -// } -// -// @Test -// fun insertOrReplace() = runBlocking { -// val row = testElement() -// queries.insertOrReplace(listOf(row)) -// assertEquals(row, queries.selectById(row.id)) -// } -// -// @Test -// fun selectById() = runBlocking { -// val rows = (0..Random.nextInt(6)).map { testElement() } -// queries.insertOrReplace(rows) -// val randomRow = rows.random() -// assertEquals(randomRow, queries.selectById(randomRow.id)) -// } -// -// @Test -// fun selectBySearchString() = runBlocking { -// val row1 = testElement().copy( -// osmJson = Json.decodeFromString("""{ "tags": { "amenity": "cafe" } }"""), -// ) -// val row2 = testElement().copy( -// osmJson = Json.decodeFromString("""{ "tags": { "amenity": "bar" } }"""), -// ) -// queries.insertOrReplace(listOf(row1, row2)) -// -// val result = queries.selectBySearchString("cafe") -// assertEquals(row1, result.singleOrNull()) -// } -// -// @Test -// fun selectByBoundingBox() = runBlocking { -// val rows = buildList { repeat(100) { add(testElement()) } } -// queries.insertOrReplace(rows) -// val london = GeoPoint(51.509865, -0.118092) -// val phuket = GeoPoint(7.878978, 98.398392) -// val boundingBox = BoundingBox.fromGeoPoints(listOf(london, phuket)) -// -// val resultRows = queries.selectByBoundingBox( -// minLat = min(boundingBox.latNorth, boundingBox.latSouth), -// maxLat = max(boundingBox.latNorth, boundingBox.latSouth), -// minLon = min(boundingBox.lonEast, boundingBox.lonWest), -// maxLon = max(boundingBox.lonEast, boundingBox.lonWest), -// ) -// -// rows.forEach { row -> -// assert( -// !boundingBox.contains( -// row.lat, -// row.lon, -// ) || resultRows.any { it.id == row.id }) -// } -// } -// -// @Test -// fun selectCategories() = runBlocking { -// val elements = listOf( -// testElement().copy(tags = JsonObject(mapOf("category" to JsonPrimitive("a")))), -// testElement().copy(tags = JsonObject(mapOf("category" to JsonPrimitive("b")))), -// ) -// queries.insertOrReplace(elements) -// assertEquals( -// listOf( -// ElementCategory("a", 1), -// ElementCategory("b", 1), -// ), queries.selectCategories() -// ) -// -// var element = testElement().copy(tags = JsonObject(mapOf("category" to JsonPrimitive("a")))) -// queries.insertOrReplace(listOf(element)) -// assertEquals(listOf( -// ElementCategory("a", 2), -// ElementCategory("b", 1), -// ), queries.selectCategories()) -// -// element = testElement().copy(tags = JsonObject(mapOf("category" to JsonPrimitive("c")))) -// queries.insertOrReplace(listOf(element)) -// assertEquals(listOf( -// ElementCategory("a", 2), -// ElementCategory("b", 1), -// ElementCategory("c", 1), -// ), queries.selectCategories()) -// } -//} -// -//fun testElement(): Element { -// return Element( -// id = "${arrayOf("node", "way", "relation").random()}:${Random.nextLong()}", -// lat = Random.nextDouble(-90.0, 90.0), -// lon = Random.nextDouble(-180.0, 180.0), -// osmJson = JsonObject(mapOf("tags" to JsonObject(emptyMap()))), -// tags = JsonObject(mapOf("icon:android" to JsonPrimitive(""))), -// createdAt = ZonedDateTime.now(ZoneOffset.UTC) -// .minusMinutes(Random.nextLong(60 * 24 * 30)), -// updatedAt = ZonedDateTime.now(ZoneOffset.UTC) -// .minusMinutes(Random.nextLong(60 * 24 * 30)), -// deletedAt = null, -// ) -//} \ No newline at end of file diff --git a/app/src/androidTest/kotlin/element/ElementsRepoTest.kt b/app/src/androidTest/kotlin/element/ElementsRepoTest.kt deleted file mode 100644 index 60ff316a..00000000 --- a/app/src/androidTest/kotlin/element/ElementsRepoTest.kt +++ /dev/null @@ -1,53 +0,0 @@ -//package element -// -//import android.app.Application -//import androidx.test.platform.app.InstrumentationRegistry -//import api.ApiImpl -//import db.inMemoryDatabase -//import kotlinx.coroutines.runBlocking -//import kotlinx.serialization.json.Json -//import kotlinx.serialization.json.JsonObject -//import kotlinx.serialization.json.JsonPrimitive -//import okhttp3.HttpUrl.Companion.toHttpUrl -//import okhttp3.OkHttpClient -//import org.junit.Assert.assertEquals -//import org.junit.Before -//import org.junit.Test -// -//class ElementsRepoTest { -// -// private lateinit var queries: ElementQueries -// -// private lateinit var repo: ElementsRepo -// -// @Before -// fun beforeEach() { -// queries = ElementQueries(inMemoryDatabase()) -// -// repo = ElementsRepo( -// api = ApiImpl( -// baseUrl = "http://localhost".toHttpUrl(), -// httpClient = OkHttpClient(), -// json = Json.Default, -// ), -// app = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as Application, -// queries = queries, -// json = Json.Default, -// ) -// } -// -// @Test -// fun selectCategories() = runBlocking { -// queries.insertOrReplace( -// listOf( -// testElement().copy(tags = JsonObject(mapOf("category" to JsonPrimitive("a")))), -// testElement().copy(tags = JsonObject(mapOf("category" to JsonPrimitive("b")))), -// ) -// ) -// -// assertEquals( -// listOf(ElementCategory("a", 1), ElementCategory("b", 1)), -// repo.selectCategories() -// ) -// } -//} \ No newline at end of file diff --git a/app/src/main/kotlin/app/App.kt b/app/src/main/kotlin/app/App.kt index e9025777..cadc7d3b 100644 --- a/app/src/main/kotlin/app/App.kt +++ b/app/src/main/kotlin/app/App.kt @@ -4,11 +4,9 @@ import android.app.Application import coil.ImageLoader import coil.ImageLoaderFactory import coil.decode.SvgDecoder -import db.persistentDatabase import org.koin.android.ext.android.get import org.koin.android.ext.koin.androidContext import org.koin.core.context.startKoin -import org.koin.dsl.module import sync.BackgroundSyncScheduler class App : Application(), ImageLoaderFactory { @@ -18,11 +16,7 @@ class App : Application(), ImageLoaderFactory { startKoin { androidContext(this@App) - - modules( - appModule, - module { single { persistentDatabase(this@App) } }, - ) + modules(appModule) } get().schedule() diff --git a/app/src/main/kotlin/app/AppModule.kt b/app/src/main/kotlin/app/AppModule.kt index 946ed681..b5fc8dd7 100644 --- a/app/src/main/kotlin/app/AppModule.kt +++ b/app/src/main/kotlin/app/AppModule.kt @@ -35,8 +35,9 @@ import user.UsersModel import user.UsersRepo import okhttp3.HttpUrl.Companion.toHttpUrl import org.koin.dsl.bind -import log.LogRecordQueries import issue.IssuesModel +import db.Database +import io.requery.android.database.sqlite.SQLiteOpenHelper val appModule = module { single { @@ -75,6 +76,8 @@ val appModule = module { ) }.bind(Api::class) + singleOf(::Database).bind(SQLiteOpenHelper::class) + singleOf(::BackgroundSyncScheduler) singleOf(::SyncNotificationController) @@ -106,8 +109,6 @@ val appModule = module { singleOf(::UsersRepo) viewModelOf(::UsersModel) - singleOf(::LogRecordQueries) - viewModelOf(::MapModel) viewModelOf(::SearchModel) diff --git a/app/src/main/kotlin/db/Database.kt b/app/src/main/kotlin/db/Database.kt index 37da2892..fe9fd8dc 100644 --- a/app/src/main/kotlin/db/Database.kt +++ b/app/src/main/kotlin/db/Database.kt @@ -8,19 +8,14 @@ import java.time.LocalDateTime val elementsUpdatedAt = MutableStateFlow(LocalDateTime.now()) -fun persistentDatabase(context: Context): SQLiteOpenHelper { - return Database(context, "btcmap-2024-04-25.db") -} +const val DB_FILE_NAME = "btcmap-2024-04-25.db" +const val DB_VERSION = 1 -fun inMemoryDatabase(): SQLiteOpenHelper { - return Database(null, null) -} - -private class Database(context: Context?, name: String?) : SQLiteOpenHelper( +class Database(context: Context) : SQLiteOpenHelper( context, - name, + DB_FILE_NAME, null, - 1, + DB_VERSION, ) { override fun onCreate(db: SQLiteDatabase) { @@ -113,16 +108,6 @@ private class Database(context: Context?, name: String?) : SQLiteOpenHelper( ); """ ) - - db.execSQL( - """ - CREATE TABLE log ( - id INTEGER PRIMARY KEY, - tags TEXT NOT NULL, - created_at TEXT NOT NULL - ); - """ - ) } override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { @@ -132,7 +117,6 @@ private class Database(context: Context?, name: String?) : SQLiteOpenHelper( db.execSQL("DROP TABLE event;") db.execSQL("DROP TABLE report;") db.execSQL("DROP TABLE user;") - db.execSQL("DROP TABLE log;") onCreate(db) } } \ No newline at end of file diff --git a/app/src/main/kotlin/element/ElementsRepo.kt b/app/src/main/kotlin/element/ElementsRepo.kt index 6d885778..19ab8b01 100644 --- a/app/src/main/kotlin/element/ElementsRepo.kt +++ b/app/src/main/kotlin/element/ElementsRepo.kt @@ -4,8 +4,6 @@ import android.app.Application import api.Api import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import log.LogRecordQueries -import org.json.JSONObject import org.osmdroid.util.BoundingBox import java.time.Duration import java.time.ZoneOffset @@ -15,7 +13,6 @@ class ElementsRepo( private val api: Api, private val app: Application, private val queries: ElementQueries, - private val logRecordQueries: LogRecordQueries, ) { suspend fun selectById(id: Long) = queries.selectById(id) @@ -150,22 +147,10 @@ class ElementsRepo( suspend fun fetchBundledElements(): Result { return runCatching { - val startMs = System.currentTimeMillis() - app.assets.open("elements.json").use { bundledElements -> withContext(Dispatchers.IO) { val elements = bundledElements.toElementsJson().map { it.toElement() } queries.insertOrReplace(elements) - - logRecordQueries.insert( - JSONObject( - mapOf( - "message" to "fetched bundled elements", - "count" to elements.size.toLong(), - "time_ms" to System.currentTimeMillis() - startMs, - ) - ) - ) } } } diff --git a/app/src/main/kotlin/log/LogRecord.kt b/app/src/main/kotlin/log/LogRecord.kt deleted file mode 100644 index a772cde8..00000000 --- a/app/src/main/kotlin/log/LogRecord.kt +++ /dev/null @@ -1,9 +0,0 @@ -package log - -import org.json.JSONObject - -data class LogRecord( - val id: Long, - val tags: JSONObject, - val createdAt: String, -) diff --git a/app/src/main/kotlin/log/LogRecordQueries.kt b/app/src/main/kotlin/log/LogRecordQueries.kt deleted file mode 100644 index 4e15d725..00000000 --- a/app/src/main/kotlin/log/LogRecordQueries.kt +++ /dev/null @@ -1,15 +0,0 @@ -package log - -import io.requery.android.database.sqlite.SQLiteOpenHelper -import org.json.JSONObject -import java.time.OffsetDateTime - -class LogRecordQueries(private val db: SQLiteOpenHelper) { - - fun insert(tags: JSONObject) { - db.writableDatabase.execSQL( - "INSERT INTO log(tags, created_at) VALUES (?, ?);", - arrayOf(tags, OffsetDateTime.now()), - ) - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/sync/Sync.kt b/app/src/main/kotlin/sync/Sync.kt index 437777e0..d495a3df 100644 --- a/app/src/main/kotlin/sync/Sync.kt +++ b/app/src/main/kotlin/sync/Sync.kt @@ -14,8 +14,6 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.withContext -import log.LogRecordQueries -import org.json.JSONObject import user.UsersRepo import java.time.Duration import java.time.ZoneOffset @@ -28,7 +26,6 @@ class Sync( private val reportsRepo: ReportsRepo, private val usersRepo: UsersRepo, private val eventsRepo: EventsRepo, - private val logRecordQueries: LogRecordQueries, private val syncNotificationController: SyncNotificationController, ) { @@ -51,8 +48,6 @@ class Sync( runCatching { withContext(Dispatchers.IO) { - logRecordQueries.insert(JSONObject(mapOf("message" to "started sync"))) - if (elementsRepo.selectCount() == 0L && elementsRepo.hasBundledElements()) { elementsRepo.fetchBundledElements().getOrThrow() }