Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 63c12cc

Browse files
committed
update osmunda
1 parent fff6671 commit 63c12cc

3 files changed

Lines changed: 36 additions & 22 deletions

File tree

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
package moe.sunjiao.osmunda
22

33
import android.content.Context
4+
import android.database.sqlite.SQLiteDatabase
5+
import moe.sunjiao.osmunda.model.Address
6+
import moe.sunjiao.osmunda.model.SearchResult
47
import java.io.File
58
import java.io.FilenameFilter
69
import java.util.*
710
import kotlin.collections.ArrayList
811

9-
class Osmunda {
10-
fun getDatabaseList(context: Context) : Array<File>?{
11-
val path = File(context.filesDir.absolutePath.replace("files", "osmunda"))
12-
return path.listFiles { dir, name -> name.toLowerCase(Locale.ROOT).endsWith(".sqlite") }
12+
class Osmunda(val context: Context) {
13+
14+
fun getDatabaseList() : Array<File>?{
15+
return getOsmundaDir()
16+
.listFiles { dir, name -> name.toLowerCase(Locale.ROOT).endsWith(".sqlite") }
17+
}
18+
19+
fun getDatabaseByName(name : String): SQLiteDatabase{
20+
return context.openOrCreateDatabase(getOsmundaDir().absolutePath + "/" + name + "sqlite", 0, null)
21+
}
22+
23+
fun getOsmundaDir(): File{
24+
return File(context.filesDir.absolutePath + "/osmunda")
1325
}
26+
1427
}

osmunda/src/main/java/moe/sunjiao/osmunda/model/Address.kt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ import android.database.sqlite.SQLiteDatabase
55
import java.sql.PreparedStatement
66

77
class Address(databaseId: Long, database: SQLiteDatabase) {
8-
var state: String? = null
9-
var city: String? = null
10-
var postcode: String? = null
11-
var housenumber: String? = null
8+
var state: String = ""
9+
var city: String = ""
10+
var postcode: String = ""
11+
var housenumber: String = ""
1212

13-
var fullAddress: String? = null
14-
var address_source: String? = null
15-
var country: String? = null
16-
var county: String? = null
17-
var housename: String? = null
18-
var unit: String? = null
19-
var street: String? = null
20-
var street_1: String? = null
21-
var street_2: String? = null
22-
var street_3: String? = null
13+
var fullAddress: String = ""
14+
var address_source: String = ""
15+
var country: String = ""
16+
var county: String = ""
17+
var housename: String = ""
18+
var unit: String = ""
19+
var street: String = ""
20+
var street_1: String = ""
21+
var street_2: String = ""
22+
var street_3: String = ""
2323

24-
var phone: String? = null
25-
var website: String? = null
24+
var phone: String = ""
25+
var website: String = ""
2626

2727
init {
2828
try {
@@ -78,6 +78,7 @@ class Address(databaseId: Long, database: SQLiteDatabase) {
7878
} catch (ex: Exception) {
7979
throw ex
8080
} finally {
81+
fullAddress = housenumber + ", " + housename + ", " + street_3 + ", " + street_2 + ", " + street_1 + ", " + street + ", " + county + ", " + city + ", " + state + ", " + country + " (" + postcode + ", " + phone + ", " + website + ")"
8182
}
8283
}
8384
}

osmunda/src/main/java/moe/sunjiao/osmunda/reader/SQLiteWriter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.Context
55
import android.database.sqlite.SQLiteConstraintException
66
import android.database.sqlite.SQLiteDatabase
77
import android.util.Log
8+
import moe.sunjiao.osmunda.Osmunda
89
import moe.sunjiao.osmunda.model.OsmType
910
import org.openstreetmap.osmosis.core.domain.v0_6.*
1011

@@ -23,8 +24,7 @@ class SQLiteWriter (context : Context, databaseName: String, private val commitF
2324
private var memberValuesList = ArrayList<ContentValues>()
2425

2526
init{
26-
database = context.openOrCreateDatabase(context.filesDir.absolutePath.replace("files", "osmunda")
27-
+ "/" + databaseName + ".sqlite", 0, null)
27+
database = Osmunda(context).getDatabaseByName(databaseName)
2828
database.execSQL("CREATE TABLE IF NOT EXISTS \"nodes\" (\"id\" INTEGER PRIMARY KEY NOT NULL , \"lat\" DOUBLE NOT NULL , \"lon\" DOUBLE NOT NULL , \"version\" INTEGER, \"timestamp\" DATETIME, \"uid\" INTEGER, \"user\" TEXT, \"changeset\" INTEGER)")
2929
database.execSQL("CREATE TABLE IF NOT EXISTS \"relation_members\" (\"type\" TEXT NOT NULL , \"member_id\" INTEGER NOT NULL , \"role\" TEXT, \"relation_id\" INTEGER NOT NULL,\"insert_id\" INTEGER NOT NULL, PRIMARY KEY( \"relation_id\",\"member_id\",\"insert_id\" ))")
3030
database.execSQL("CREATE TABLE IF NOT EXISTS \"relations\" (\"id\" INTEGER PRIMARY KEY NOT NULL , \"user\" TEXT, \"uid\" INTEGER, \"version\" INTEGER, \"changeset\" INTEGER, \"timestamp\" BIGINT)")

0 commit comments

Comments
 (0)