Skip to content

Commit

Permalink
atmlocator converted to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
pblachut committed Apr 26, 2016
1 parent a6d1a39 commit 04e3297
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {

private fun addMarkerForAtm(atm: Atm) {
val sydney = LatLng(atm.latitude, atm.longitude)
mMap?.addMarker(MarkerOptions().position(sydney).title(atm.bank.name).snippet(atm.bank.phone))
mMap?.addMarker(MarkerOptions().position(sydney).title(atm.bank?.name).snippet(atm.bank?.phone))
mMap?.moveCamera(CameraUpdateFactory.newLatLng(sydney))

}
Expand Down
74 changes: 0 additions & 74 deletions AtmLocator/app/src/main/java/piotrek/atmlocator/orm/Atm.java

This file was deleted.

30 changes: 30 additions & 0 deletions AtmLocator/app/src/main/java/piotrek/atmlocator/orm/Atm.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package piotrek.atmlocator.orm

import com.j256.ormlite.field.DatabaseField
import com.j256.ormlite.table.DatabaseTable
import piotrek.atmlocator.orm.Atm.Columns.ID

/**
* Created by Admin on 2016-04-26.
*/

@DatabaseTable(tableName = "atm", daoClass = AtmDao::class)
class Atm {
@DatabaseField(generatedId = true, columnName = ID)
var id: Int = 0

// eager loading
//@DatabaseField(foreign = true, foreignAutoRefresh = true)
@DatabaseField(foreign = true)
var bank: Bank? = null
@DatabaseField(canBeNull = false)
var longitude: Double = 0.toDouble()
@DatabaseField(canBeNull = false)
var latitude: Double = 0.toDouble()
@DatabaseField(canBeNull = false)
var address: String? = null

object Columns {
const val ID = "id"
}
}
24 changes: 0 additions & 24 deletions AtmLocator/app/src/main/java/piotrek/atmlocator/orm/AtmDao.java

This file was deleted.

24 changes: 24 additions & 0 deletions AtmLocator/app/src/main/java/piotrek/atmlocator/orm/AtmDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package piotrek.atmlocator.orm

import com.j256.ormlite.dao.BaseDaoImpl
import com.j256.ormlite.support.ConnectionSource
import com.j256.ormlite.table.DatabaseTableConfig

import java.sql.SQLException

/**
* Created by Admin on 2016-04-26.
*/
class AtmDao : BaseDaoImpl<Atm, Int> {
@Throws(SQLException::class)
protected constructor(dataClass: Class<Atm>) : super(dataClass) {
}

@Throws(SQLException::class)
protected constructor(connectionSource: ConnectionSource, dataClass: Class<Atm>) : super(connectionSource, dataClass) {
}

@Throws(SQLException::class)
protected constructor(connectionSource: ConnectionSource, tableConfig: DatabaseTableConfig<Atm>) : super(connectionSource, tableConfig) {
}
}
59 changes: 0 additions & 59 deletions AtmLocator/app/src/main/java/piotrek/atmlocator/orm/Bank.java

This file was deleted.

30 changes: 30 additions & 0 deletions AtmLocator/app/src/main/java/piotrek/atmlocator/orm/Bank.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package piotrek.atmlocator.orm

import com.j256.ormlite.field.DatabaseField
import com.j256.ormlite.table.DatabaseTable

@DatabaseTable(tableName = "bank", daoClass = BankDao::class)
class Bank() {

@DatabaseField(generatedId = true, columnName = Columns.ID)
var id: Int = 0
@DatabaseField(columnName = Columns.BANK_NAME, canBeNull = false, unique = true)
var name: String? = null
@DatabaseField(columnName = Columns.PHONE)
var phone: String? = null

override fun toString(): String {
return name ?: ""
}

constructor(name: String, phone: String) : this() {
this.name = name
this.phone = phone
}

object Columns {
const val ID = "id"
const val BANK_NAME = "bank_name"
const val PHONE = "phone"
}
}
24 changes: 0 additions & 24 deletions AtmLocator/app/src/main/java/piotrek/atmlocator/orm/BankDao.java

This file was deleted.

24 changes: 24 additions & 0 deletions AtmLocator/app/src/main/java/piotrek/atmlocator/orm/BankDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package piotrek.atmlocator.orm

import com.j256.ormlite.dao.BaseDaoImpl
import com.j256.ormlite.support.ConnectionSource
import com.j256.ormlite.table.DatabaseTableConfig

import java.sql.SQLException

/**
* Created by Admin on 2016-04-26.
*/
class BankDao : BaseDaoImpl<Bank, Int> {
@Throws(SQLException::class)
protected constructor(dataClass: Class<Bank>) : super(dataClass) {
}

@Throws(SQLException::class)
protected constructor(connectionSource: ConnectionSource, dataClass: Class<Bank>) : super(connectionSource, dataClass) {
}

@Throws(SQLException::class)
protected constructor(connectionSource: ConnectionSource, tableConfig: DatabaseTableConfig<Bank>) : super(connectionSource, tableConfig) {
}
}
49 changes: 0 additions & 49 deletions AtmLocator/app/src/main/java/piotrek/atmlocator/orm/DbHelper.java

This file was deleted.

Loading

0 comments on commit 04e3297

Please sign in to comment.