|
|
|
|
@ -2,20 +2,16 @@ package net.pokeranalytics.android.model.realm |
|
|
|
|
|
|
|
|
|
import com.google.android.libraries.places.api.model.Place |
|
|
|
|
import io.realm.RealmObject |
|
|
|
|
import io.realm.annotations.Ignore |
|
|
|
|
import io.realm.annotations.PrimaryKey |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Manageable |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.LocationRow |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open class Location : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable { |
|
|
|
|
open class Location : RealmObject(), Manageable, RowRepresentable { |
|
|
|
|
|
|
|
|
|
@PrimaryKey |
|
|
|
|
var id = UUID.randomUUID().toString() |
|
|
|
|
@ -32,9 +28,6 @@ open class Location : RealmObject(), Manageable, StaticRowRepresentableDataSourc |
|
|
|
|
// the latitude of the location |
|
|
|
|
var latitude: Double? = null |
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
|
var isLookingForPlaces = false |
|
|
|
|
|
|
|
|
|
override fun getDisplayName(): String { |
|
|
|
|
return this.name |
|
|
|
|
} |
|
|
|
|
@ -43,54 +36,12 @@ open class Location : RealmObject(), Manageable, StaticRowRepresentableDataSourc |
|
|
|
|
return this.id |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
val rows = ArrayList<RowRepresentable>() |
|
|
|
|
rows.add(SimpleRow.NAME) |
|
|
|
|
rows.addAll(LocationRow.values()) |
|
|
|
|
return rows |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun stringForRow(row: RowRepresentable): String { |
|
|
|
|
return when (row) { |
|
|
|
|
SimpleRow.NAME -> this.name |
|
|
|
|
LocationRow.ADDRESS -> this.address |
|
|
|
|
else -> return super.stringForRow(row) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun boolForRow(row: RowRepresentable): Boolean { |
|
|
|
|
return when(row) { |
|
|
|
|
LocationRow.LOCATE_ME -> return isLookingForPlaces |
|
|
|
|
else -> super.boolForRow(row) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun editDescriptors(row: RowRepresentable): ArrayList<RowRepresentableEditDescriptor> { |
|
|
|
|
val data = java.util.ArrayList<RowRepresentableEditDescriptor>() |
|
|
|
|
when (row) { |
|
|
|
|
SimpleRow.NAME -> data.add( |
|
|
|
|
RowRepresentableEditDescriptor( |
|
|
|
|
this.name, |
|
|
|
|
SimpleRow.NAME.resId |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
LocationRow.ADDRESS -> data.add( |
|
|
|
|
RowRepresentableEditDescriptor( |
|
|
|
|
this.address, |
|
|
|
|
LocationRow.ADDRESS.resId |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
return data |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun updateValue(value: Any?, row: RowRepresentable) { |
|
|
|
|
|
|
|
|
|
when (row) { |
|
|
|
|
SimpleRow.NAME -> this.name = value as String? ?: "" |
|
|
|
|
LocationRow.ADDRESS -> this.address = value as String? ?: "" |
|
|
|
|
LocationRow.LOCATE_ME -> { |
|
|
|
|
isLookingForPlaces = false |
|
|
|
|
if (value is Place) { |
|
|
|
|
setPlace(value) |
|
|
|
|
} |
|
|
|
|
@ -109,7 +60,7 @@ open class Location : RealmObject(), Manageable, StaticRowRepresentableDataSourc |
|
|
|
|
/** |
|
|
|
|
* Fill the location attributes with a place object |
|
|
|
|
*/ |
|
|
|
|
fun setPlace(place: Place) { |
|
|
|
|
private fun setPlace(place: Place) { |
|
|
|
|
this.name = place.name ?: "" |
|
|
|
|
this.address = place.address ?: "" |
|
|
|
|
this.latitude = place.latLng?.latitude |
|
|
|
|
|