From 167695bccb194a45e8728ee5c097c90e2445758d Mon Sep 17 00:00:00 2001 From: Piruin Panichphol Date: Sun, 3 Mar 2019 02:14:11 +0700 Subject: [PATCH 01/10] draft switch maps info --- ffc/src/main/kotlin/ffc/app/MainActivity.kt | 3 + .../ffc/app/location/GeoMapsFragment.kt | 93 +++++++++++++++---- .../ffc/app/location/GeoMapsInfoSheet.kt | 52 +++++++++++ .../res/drawable/ic_marker_home_grey_24dp.xml | 13 +++ .../drawable/ic_marker_home_yellow_24dp.xml | 13 +++ .../main/res/layout/activity_main_content.xml | 4 + .../main/res/layout/activity_main_sheet.xml | 68 ++++++++++++++ ffc/src/main/res/values/dimens.xml | 1 + 8 files changed, 228 insertions(+), 19 deletions(-) create mode 100644 ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt create mode 100644 ffc/src/main/res/drawable/ic_marker_home_grey_24dp.xml create mode 100644 ffc/src/main/res/drawable/ic_marker_home_yellow_24dp.xml create mode 100644 ffc/src/main/res/layout/activity_main_sheet.xml diff --git a/ffc/src/main/kotlin/ffc/app/MainActivity.kt b/ffc/src/main/kotlin/ffc/app/MainActivity.kt index be2aed26..26102164 100644 --- a/ffc/src/main/kotlin/ffc/app/MainActivity.kt +++ b/ffc/src/main/kotlin/ffc/app/MainActivity.kt @@ -37,6 +37,7 @@ import ffc.android.setTransition import ffc.android.viewModel import ffc.app.auth.auth import ffc.app.location.GeoMapsFragment +import ffc.app.location.GeoMapsInfoSheet import ffc.app.location.housesOf import ffc.app.search.SearchActivity import ffc.app.setting.AboutActivity @@ -87,6 +88,8 @@ class MainActivity : FamilyFolderActivity(), NavigationView.OnNavigationItemSele observe(viewModel.houseNoLocation) { if (it == true) addLocationButton.show() else addLocationButton.hide() } + + GeoMapsInfoSheet(this, geoMapsFragment) } private fun setupNavigationDrawer() { diff --git a/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt b/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt index 504730ed..6531fe44 100644 --- a/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt +++ b/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt @@ -20,14 +20,17 @@ package ffc.app.location import android.app.Activity import android.arch.lifecycle.MutableLiveData import android.arch.lifecycle.ViewModel +import android.content.Context import android.content.Intent import android.os.Bundle import android.support.annotation.DrawableRes import android.support.design.widget.FloatingActionButton import com.google.android.gms.maps.GoogleMap +import com.google.android.gms.maps.model.BitmapDescriptor import com.google.android.gms.maps.model.BitmapDescriptorFactory import com.google.android.gms.maps.model.CameraPosition import com.google.android.gms.maps.model.LatLng +import com.google.maps.android.data.geojson.GeoJsonFeature import com.google.maps.android.data.geojson.GeoJsonLayer import com.google.maps.android.data.geojson.GeoJsonPointStyle import com.sembozdemir.permissionskt.handlePermissionsResult @@ -41,7 +44,9 @@ import ffc.android.viewModel import ffc.app.R import ffc.app.dev import ffc.app.familyFolderActivity +import ffc.app.location.GeoMapsInfo.ELDER import ffc.app.util.alert.handle +import ffc.app.util.md5 import ffc.entity.gson.toJson import ffc.entity.place.House import me.piruin.geok.geometry.FeatureCollection @@ -63,6 +68,7 @@ class GeoMapsFragment : PointMarloFragment() { private val preference by lazy { GeoPreferences(context!!, org) } private val org by lazy { familyFolderActivity.org } + lateinit var markerStyles: MarkerStyles override fun onActivityCreated(bundle: Bundle?) { super.onActivityCreated(bundle) @@ -71,6 +77,7 @@ class GeoMapsFragment : PointMarloFragment() { viewFinder.gone() hideToolsMenu() observeViewModel() + markerStyles = ChronicMarkerStyles(context!!) } private fun observeViewModel() { @@ -84,7 +91,8 @@ class GeoMapsFragment : PointMarloFragment() { ?: preferZoomLevel ) googleMap.clear() - addGeoJsonLayer(GeoJsonLayer(googleMap, JSONObject(it.toJson()))) + viewModel.json.value = JSONObject(it.toJson()) + addGeoJsonLayer(GeoJsonLayer(googleMap, viewModel.json.value)) preference.geojsonCache = it } } @@ -105,13 +113,13 @@ class GeoMapsFragment : PointMarloFragment() { override fun onMapReady(googleMap: GoogleMap?) { super.onMapReady(googleMap) viewModel.geojson.value = doAsyncResult { preference.geojsonCache }.get() - addLocationButton?.setOnClickListener { - val intent = intentFor( - "target" to googleMap!!.cameraPosition.target, - "zoom" to googleMap.cameraPosition.zoom - ) - startActivityForResult(intent, REQ_ADD_LOCATION) - } +// addLocationButton?.setOnClickListener { +// val intent = intentFor( +// "target" to googleMap!!.cameraPosition.target, +// "zoom" to googleMap.cameraPosition.zoom +// ) +// startActivityForResult(intent, REQ_ADD_LOCATION) +// } askMyLocationPermission() loadGeoJson() } @@ -128,13 +136,7 @@ class GeoMapsFragment : PointMarloFragment() { private fun addGeoJsonLayer(layer: GeoJsonLayer) { with(layer) { - features.forEach { - it.pointStyle = GeoJsonPointStyle().apply { - icon = if (it.getProperty("haveChronic") == "true") chronicHomeIcon else homeIcon - title = "บ้านเลขที่ ${it.getProperty("no")}" - snippet = it.getProperty("coordinates")?.trimMargin() - } - } + features.forEach { it.pointStyle = markerStyles.pointStyleOf(it) } setOnFeatureClickListener { feature -> val intent = intentFor("houseId" to feature.getProperty("id")) startActivityForResult(intent, REQ_ADD_LOCATION, activity!!.sceneTransition()) @@ -161,14 +163,67 @@ class GeoMapsFragment : PointMarloFragment() { googleMap?.cameraPosition?.let { preference.lastCameraPosition = it } } - fun bitmapOf(@DrawableRes resId: Int) = BitmapDescriptorFactory.fromBitmap(context!!.drawable(resId).toBitmap()) - - private val homeIcon by lazy { bitmapOf(R.drawable.ic_marker_home_green_24dp) } + fun showInfo(info: GeoMapsInfo) { + markerStyles = when (info) { + ELDER -> ElderMarkerStyle(context!!) + else -> ChronicMarkerStyles(context!!) + } - private val chronicHomeIcon by lazy { bitmapOf(R.drawable.ic_marker_home_red_24dp) } + viewModel.json.value?.let { + googleMap.clear() + addGeoJsonLayer(GeoJsonLayer(googleMap, it)) + } + } class GeoViewModel : ViewModel() { val geojson = MutableLiveData>() + val json = MutableLiveData() val exception = MutableLiveData() } + + interface MarkerStyles { + + val context: Context + + fun bitmapOf(@DrawableRes resId: Int): BitmapDescriptor = + BitmapDescriptorFactory.fromBitmap(context.drawable(resId).toBitmap()) + + fun pointStyleOf(it: GeoJsonFeature): GeoJsonPointStyle + } + + class ChronicMarkerStyles(override val context: Context) : MarkerStyles { + + private val homeIcon by lazy { bitmapOf(R.drawable.ic_marker_home_green_24dp) } + + private val chronicHomeIcon by lazy { bitmapOf(R.drawable.ic_marker_home_red_24dp) } + + override fun pointStyleOf(it: GeoJsonFeature): GeoJsonPointStyle { + return GeoJsonPointStyle().apply { + icon = if (it.getProperty("haveChronic") == "true") chronicHomeIcon else homeIcon + title = "บ้านเลขที่ ${it.getProperty("no")}" + snippet = it.getProperty("coordinates")?.trimMargin() + } + } + } + + class ElderMarkerStyle(override val context: Context) : MarkerStyles { + + private val notElderIcon by lazy { bitmapOf(R.drawable.ic_marker_home_grey_24dp) } + private val socialIcon by lazy { bitmapOf(R.drawable.ic_marker_home_green_24dp) } + private val stayIcon by lazy { bitmapOf(R.drawable.ic_marker_home_yellow_24dp) } + private val bedIcon by lazy { bitmapOf(R.drawable.ic_marker_home_red_24dp) } + + override fun pointStyleOf(it: GeoJsonFeature): GeoJsonPointStyle { + return GeoJsonPointStyle().apply { + val md5 = it.getProperty("no").md5().toLowerCase() + icon = when (md5[0]) { + '1' -> bedIcon + '4', '5' -> stayIcon + '6', '8', 'a' -> socialIcon + else -> notElderIcon + } + title = md5 + } + } + } } diff --git a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt new file mode 100644 index 00000000..7531527c --- /dev/null +++ b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt @@ -0,0 +1,52 @@ +package ffc.app.location + +import android.support.design.widget.BottomSheetBehavior +import android.support.design.widget.BottomSheetBehavior.BottomSheetCallback +import android.support.design.widget.FloatingActionButton +import android.view.View +import ffc.android.onClick +import ffc.app.MainActivity +import ffc.app.R +import org.jetbrains.anko.find +import org.jetbrains.anko.toast + +class GeoMapsInfoSheet(val actvity: MainActivity, geoMapsFragment: GeoMapsFragment) { + + val fab = actvity.find(R.id.addLocationButton) + val behavior = BottomSheetBehavior.from(actvity.find(R.id.bottom_sheet)) + + init { + behavior.state = BottomSheetBehavior.STATE_HIDDEN + behavior.setBottomSheetCallback(object : BottomSheetCallback() { + override fun onSlide(view: View, slideOffset: Float) { + } + + override fun onStateChanged(view: View, newState: Int) { + if (BottomSheetBehavior.STATE_SETTLING == newState) { + fab.animate().scaleX(0f).scaleY(0f).setDuration(300).start() + } else if (BottomSheetBehavior.STATE_HIDDEN == newState) { + fab.animate().scaleX(1f).scaleY(1f).setDuration(300).start() + } + } + }) + actvity.find(R.id.elderMapInfo).onClick { + actvity.toast("elder") + geoMapsFragment.showInfo(GeoMapsInfo.ELDER) + behavior.state = BottomSheetBehavior.STATE_COLLAPSED + } + actvity.find(R.id.cvdMapInfo).onClick { + actvity.toast("chronic") + geoMapsFragment.showInfo(GeoMapsInfo.Chronic) + behavior.state = BottomSheetBehavior.STATE_COLLAPSED + } + + + fab.onClick { + behavior.state = BottomSheetBehavior.STATE_COLLAPSED + } + } +} + +enum class GeoMapsInfo { + ELDER, Chronic, Disability +} diff --git a/ffc/src/main/res/drawable/ic_marker_home_grey_24dp.xml b/ffc/src/main/res/drawable/ic_marker_home_grey_24dp.xml new file mode 100644 index 00000000..7cd3e861 --- /dev/null +++ b/ffc/src/main/res/drawable/ic_marker_home_grey_24dp.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/ffc/src/main/res/drawable/ic_marker_home_yellow_24dp.xml b/ffc/src/main/res/drawable/ic_marker_home_yellow_24dp.xml new file mode 100644 index 00000000..e4aabc17 --- /dev/null +++ b/ffc/src/main/res/drawable/ic_marker_home_yellow_24dp.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/ffc/src/main/res/layout/activity_main_content.xml b/ffc/src/main/res/layout/activity_main_content.xml index e46c8e8f..f0945191 100644 --- a/ffc/src/main/res/layout/activity_main_content.xml +++ b/ffc/src/main/res/layout/activity_main_content.xml @@ -69,6 +69,8 @@ tools:text="version 4.0.0-10-6167342-photo-dirty" /> + + diff --git a/ffc/src/main/res/layout/activity_main_sheet.xml b/ffc/src/main/res/layout/activity_main_sheet.xml new file mode 100644 index 00000000..0cfc9220 --- /dev/null +++ b/ffc/src/main/res/layout/activity_main_sheet.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ffc/src/main/res/values/dimens.xml b/ffc/src/main/res/values/dimens.xml index e064c084..93cf56f8 100644 --- a/ffc/src/main/res/values/dimens.xml +++ b/ffc/src/main/res/values/dimens.xml @@ -17,6 +17,7 @@ 90dp + 20dp 24dp 24dp From e06ff9ba77f18dd50d61dc644220b1e9f35902ec Mon Sep 17 00:00:00 2001 From: Piruin Panichphol Date: Sun, 3 Mar 2019 15:23:09 +0700 Subject: [PATCH 02/10] improve responsibility on switch info type --- .../ffc/app/location/BaseMapsFragment.kt | 61 +++++++++++++++++ .../ffc/app/location/GeoMapsFragment.kt | 67 ++++++++----------- .../ffc/app/location/GeoMapsInfoSheet.kt | 41 +++++++----- ffc/src/main/kotlin/ffc/app/util/Iterable.kt | 13 ++++ .../res/drawable/ic_marker_home_grey_24dp.xml | 2 +- .../main/res/layout/activity_main_sheet.xml | 3 - 6 files changed, 130 insertions(+), 57 deletions(-) create mode 100644 ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt create mode 100644 ffc/src/main/kotlin/ffc/app/util/Iterable.kt diff --git a/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt b/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt new file mode 100644 index 00000000..88057991 --- /dev/null +++ b/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt @@ -0,0 +1,61 @@ +package ffc.app.location + +import android.os.Bundle +import com.google.android.gms.maps.GoogleMap +import com.google.android.gms.maps.model.CameraPosition +import com.google.android.gms.maps.model.LatLng +import com.sembozdemir.permissionskt.handlePermissionsResult +import ffc.android.gone +import ffc.app.familyFolderActivity +import th.or.nectec.marlo.MarloFragment + +open class BaseMapsFragment : MarloFragment() { + + private val org by lazy { familyFolderActivity.org } + internal val preference by lazy { GeoPreferences(context!!, org) } + + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) + setStartLocation(preference.lastCameraPosition!!) + viewFinder.gone() + hideToolsMenu() + } + + private fun setStartLocation(lastPosition: CameraPosition?) { + if (lastPosition != null) { + setStartLocation(lastPosition.target, lastPosition.zoom) + } else { + setStartLocation(LatLng(13.76498, 100.538335), 5.0f) + setStartAtCurrentLocation(true) + } + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, + grantResults: IntArray) { + activity!!.handlePermissionsResult(requestCode, permissions, grantResults) + } + + override fun onPause() { + super.onPause() + googleMap?.cameraPosition?.let { preference.lastCameraPosition = it } + } + + override fun onMapReady(googleMap: GoogleMap?) { + super.onMapReady(googleMap) + askMyLocationPermission() + } + + override fun showToolsMenu() { + //do nothing + } + + override fun undo() = true + + override fun hideToolsMenu() { + //do nothing + } + + override fun mark(markPoint: LatLng?) { + //do nothing + } +} diff --git a/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt b/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt index 6531fe44..deb90877 100644 --- a/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt +++ b/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt @@ -28,14 +28,10 @@ import android.support.design.widget.FloatingActionButton import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.model.BitmapDescriptor import com.google.android.gms.maps.model.BitmapDescriptorFactory -import com.google.android.gms.maps.model.CameraPosition -import com.google.android.gms.maps.model.LatLng import com.google.maps.android.data.geojson.GeoJsonFeature import com.google.maps.android.data.geojson.GeoJsonLayer import com.google.maps.android.data.geojson.GeoJsonPointStyle -import com.sembozdemir.permissionskt.handlePermissionsResult import ffc.android.drawable -import ffc.android.gone import ffc.android.observe import ffc.android.rawAs import ffc.android.sceneTransition @@ -46,18 +42,20 @@ import ffc.app.dev import ffc.app.familyFolderActivity import ffc.app.location.GeoMapsInfo.ELDER import ffc.app.util.alert.handle +import ffc.app.util.forEachChunk import ffc.app.util.md5 import ffc.entity.gson.toJson import ffc.entity.place.House import me.piruin.geok.geometry.FeatureCollection import me.piruin.geok.geometry.Point -import org.jetbrains.anko.doAsyncResult +import org.jetbrains.anko.doAsync import org.jetbrains.anko.find import org.jetbrains.anko.support.v4.intentFor +import org.jetbrains.anko.support.v4.onUiThread import org.json.JSONObject -import th.or.nectec.marlo.PointMarloFragment +import timber.log.Timber -class GeoMapsFragment : PointMarloFragment() { +class GeoMapsFragment : BaseMapsFragment() { val REQ_ADD_LOCATION = 1032 @@ -65,17 +63,13 @@ class GeoMapsFragment : PointMarloFragment() { private var addLocationButton: FloatingActionButton? = null private val viewModel by lazy { viewModel() } - private val preference by lazy { GeoPreferences(context!!, org) } - private val org by lazy { familyFolderActivity.org } lateinit var markerStyles: MarkerStyles - override fun onActivityCreated(bundle: Bundle?) { - super.onActivityCreated(bundle) - setStartLocation(preference.lastCameraPosition) + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) addLocationButton = activity!!.find(R.id.addLocationButton) - viewFinder.gone() - hideToolsMenu() + observeViewModel() markerStyles = ChronicMarkerStyles(context!!) } @@ -93,7 +87,6 @@ class GeoMapsFragment : PointMarloFragment() { googleMap.clear() viewModel.json.value = JSONObject(it.toJson()) addGeoJsonLayer(GeoJsonLayer(googleMap, viewModel.json.value)) - preference.geojsonCache = it } } observe(viewModel.exception) { @@ -101,18 +94,11 @@ class GeoMapsFragment : PointMarloFragment() { } } - private fun setStartLocation(lastPosition: CameraPosition?) { - if (lastPosition != null) { - setStartLocation(lastPosition.target, lastPosition.zoom) - } else { - setStartLocation(LatLng(13.76498, 100.538335), 5.0f) - setStartAtCurrentLocation(true) - } - } + override fun onMapReady(googleMap: GoogleMap?) { super.onMapReady(googleMap) - viewModel.geojson.value = doAsyncResult { preference.geojsonCache }.get() +// viewModel.geojson.value = doAsyncResult { preference.geojsonCache }.get() // addLocationButton?.setOnClickListener { // val intent = intentFor( // "target" to googleMap!!.cameraPosition.target, @@ -120,7 +106,6 @@ class GeoMapsFragment : PointMarloFragment() { // ) // startActivityForResult(intent, REQ_ADD_LOCATION) // } - askMyLocationPermission() loadGeoJson() } @@ -143,6 +128,7 @@ class GeoMapsFragment : PointMarloFragment() { } addLayerToMap() } + viewModel.layer.value = layer } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { @@ -154,30 +140,34 @@ class GeoMapsFragment : PointMarloFragment() { } } - override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { - activity!!.handlePermissionsResult(requestCode, permissions, grantResults) - } - - override fun onPause() { - super.onPause() - googleMap?.cameraPosition?.let { preference.lastCameraPosition = it } - } - - fun showInfo(info: GeoMapsInfo) { + fun showInfo(info: GeoMapsInfo, onProgress: (Double) -> Unit) { markerStyles = when (info) { ELDER -> ElderMarkerStyle(context!!) else -> ChronicMarkerStyles(context!!) } - viewModel.json.value?.let { - googleMap.clear() - addGeoJsonLayer(GeoJsonLayer(googleMap, it)) + viewModel.layer.value?.let { layer -> + googleMap.uiSettings.setAllGesturesEnabled(false) + doAsync { + layer.features.forEachChunk(200, 150) { progress, list -> + onUiThread { + list.forEach { + it.pointStyle = markerStyles.pointStyleOf(it) + } + onProgress(progress) + } + } + Timber.d("finish") + onUiThread { googleMap.uiSettings.setAllGesturesEnabled(true) } + } } } + class GeoViewModel : ViewModel() { val geojson = MutableLiveData>() val json = MutableLiveData() + val layer = MutableLiveData() val exception = MutableLiveData() } @@ -227,3 +217,4 @@ class GeoMapsFragment : PointMarloFragment() { } } } + diff --git a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt index 7531527c..f7c0d2c1 100644 --- a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt +++ b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt @@ -4,16 +4,36 @@ import android.support.design.widget.BottomSheetBehavior import android.support.design.widget.BottomSheetBehavior.BottomSheetCallback import android.support.design.widget.FloatingActionButton import android.view.View +import android.view.View.OnClickListener import ffc.android.onClick import ffc.app.MainActivity import ffc.app.R +import ffc.app.location.GeoMapsInfo.Chronic +import ffc.app.location.GeoMapsInfo.ELDER +import ffc.app.location.GeoMapsInfo.NORMAL import org.jetbrains.anko.find -import org.jetbrains.anko.toast -class GeoMapsInfoSheet(val actvity: MainActivity, geoMapsFragment: GeoMapsFragment) { +class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) { val fab = actvity.find(R.id.addLocationButton) - val behavior = BottomSheetBehavior.from(actvity.find(R.id.bottom_sheet)) + private val behavior = BottomSheetBehavior.from(actvity.find(R.id.bottom_sheet))!! + + var currentInfo: GeoMapsInfo = NORMAL + + val onClick = OnClickListener { + val newInfo = when (it.id) { + R.id.elderMapInfo -> ELDER + R.id.cvdMapInfo -> Chronic + else -> NORMAL + } + if (newInfo != currentInfo) { + geoMapsFragment.showInfo(newInfo) { + //TODO implement progress bar + } + currentInfo = newInfo + } + behavior.state = BottomSheetBehavior.STATE_COLLAPSED + } init { behavior.state = BottomSheetBehavior.STATE_HIDDEN @@ -29,17 +49,8 @@ class GeoMapsInfoSheet(val actvity: MainActivity, geoMapsFragment: GeoMapsFragme } } }) - actvity.find(R.id.elderMapInfo).onClick { - actvity.toast("elder") - geoMapsFragment.showInfo(GeoMapsInfo.ELDER) - behavior.state = BottomSheetBehavior.STATE_COLLAPSED - } - actvity.find(R.id.cvdMapInfo).onClick { - actvity.toast("chronic") - geoMapsFragment.showInfo(GeoMapsInfo.Chronic) - behavior.state = BottomSheetBehavior.STATE_COLLAPSED - } - + actvity.find(R.id.elderMapInfo).setOnClickListener(onClick) + actvity.find(R.id.cvdMapInfo).setOnClickListener(onClick) fab.onClick { behavior.state = BottomSheetBehavior.STATE_COLLAPSED @@ -48,5 +59,5 @@ class GeoMapsInfoSheet(val actvity: MainActivity, geoMapsFragment: GeoMapsFragme } enum class GeoMapsInfo { - ELDER, Chronic, Disability + NORMAL, ELDER, Chronic, Disability } diff --git a/ffc/src/main/kotlin/ffc/app/util/Iterable.kt b/ffc/src/main/kotlin/ffc/app/util/Iterable.kt new file mode 100644 index 00000000..db5ccfeb --- /dev/null +++ b/ffc/src/main/kotlin/ffc/app/util/Iterable.kt @@ -0,0 +1,13 @@ +package ffc.app.util + +inline fun Iterable.forEachChunk( + size: Int, + delay: Long = 0, + action: (progress: Double, list: List) -> Unit +) { + val chunked = chunked(size) + chunked.forEachIndexed { index, list -> + Thread.sleep(delay) + action(index / chunked.size.toDouble(), list) + } +} diff --git a/ffc/src/main/res/drawable/ic_marker_home_grey_24dp.xml b/ffc/src/main/res/drawable/ic_marker_home_grey_24dp.xml index 7cd3e861..8179e16f 100644 --- a/ffc/src/main/res/drawable/ic_marker_home_grey_24dp.xml +++ b/ffc/src/main/res/drawable/ic_marker_home_grey_24dp.xml @@ -5,7 +5,7 @@ android:viewportWidth="512" android:viewportHeight="512"> Date: Sun, 3 Mar 2019 16:51:41 +0700 Subject: [PATCH 03/10] implement progress on change info view --- .../ffc/app/location/GeoMapsInfoSheet.kt | 20 ++++++++++++++----- ffc/src/main/kotlin/ffc/app/util/Iterable.kt | 2 +- .../main/res/layout/activity_main_sheet.xml | 14 ++++++++++++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt index f7c0d2c1..bc74c8a7 100644 --- a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt +++ b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt @@ -5,6 +5,7 @@ import android.support.design.widget.BottomSheetBehavior.BottomSheetCallback import android.support.design.widget.FloatingActionButton import android.view.View import android.view.View.OnClickListener +import android.widget.ProgressBar import ffc.android.onClick import ffc.app.MainActivity import ffc.app.R @@ -15,22 +16,28 @@ import org.jetbrains.anko.find class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) { - val fab = actvity.find(R.id.addLocationButton) + private val fab = actvity.find(R.id.addLocationButton) + private val progress = actvity.find(R.id.progress) private val behavior = BottomSheetBehavior.from(actvity.find(R.id.bottom_sheet))!! var currentInfo: GeoMapsInfo = NORMAL - val onClick = OnClickListener { - val newInfo = when (it.id) { + val onClick = OnClickListener { view -> + val newInfo = when (view.id) { R.id.elderMapInfo -> ELDER R.id.cvdMapInfo -> Chronic else -> NORMAL } if (newInfo != currentInfo) { + currentInfo = newInfo + progress.progress = 0 geoMapsFragment.showInfo(newInfo) { - //TODO implement progress bar + progress.progress = (it * 100.0).toInt() + if (it == 1.0) { + progress.animate().scaleX(0f).setDuration(150).start() + } } - currentInfo = newInfo + progress.animate().scaleX(1f).setDuration(50).setStartDelay(300).start() } behavior.state = BottomSheetBehavior.STATE_COLLAPSED } @@ -52,6 +59,9 @@ class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) actvity.find(R.id.elderMapInfo).setOnClickListener(onClick) actvity.find(R.id.cvdMapInfo).setOnClickListener(onClick) + progress.max = 100 + progress.animate().scaleX(0f).setDuration(0).start() + fab.onClick { behavior.state = BottomSheetBehavior.STATE_COLLAPSED } diff --git a/ffc/src/main/kotlin/ffc/app/util/Iterable.kt b/ffc/src/main/kotlin/ffc/app/util/Iterable.kt index db5ccfeb..a3e48c61 100644 --- a/ffc/src/main/kotlin/ffc/app/util/Iterable.kt +++ b/ffc/src/main/kotlin/ffc/app/util/Iterable.kt @@ -8,6 +8,6 @@ inline fun Iterable.forEachChunk( val chunked = chunked(size) chunked.forEachIndexed { index, list -> Thread.sleep(delay) - action(index / chunked.size.toDouble(), list) + action((index + 1) / chunked.size.toDouble(), list) } } diff --git a/ffc/src/main/res/layout/activity_main_sheet.xml b/ffc/src/main/res/layout/activity_main_sheet.xml index 4a5ca3d5..b6ad1b4a 100644 --- a/ffc/src/main/res/layout/activity_main_sheet.xml +++ b/ffc/src/main/res/layout/activity_main_sheet.xml @@ -1,6 +1,7 @@ + + Date: Sun, 3 Mar 2019 18:13:51 +0700 Subject: [PATCH 04/10] Add loading peek and chronic legend peek --- .../ffc/app/location/GeoMapsInfoSheet.kt | 19 ++++ .../main/res/layout/activity_main_content.xml | 2 +- .../res/layout/maps_info_chronic_peek.xml | 90 +++++++++++++++++++ .../res/layout/maps_info_peek_loading.xml | 10 +++ ...ity_main_sheet.xml => maps_info_sheet.xml} | 22 ++--- ffc/src/main/res/values/dimens.xml | 1 + 6 files changed, 132 insertions(+), 12 deletions(-) create mode 100644 ffc/src/main/res/layout/maps_info_chronic_peek.xml create mode 100644 ffc/src/main/res/layout/maps_info_peek_loading.xml rename ffc/src/main/res/layout/{activity_main_sheet.xml => maps_info_sheet.xml} (86%) diff --git a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt index bc74c8a7..fe3b8a56 100644 --- a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt +++ b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt @@ -5,7 +5,9 @@ import android.support.design.widget.BottomSheetBehavior.BottomSheetCallback import android.support.design.widget.FloatingActionButton import android.view.View import android.view.View.OnClickListener +import android.view.ViewGroup import android.widget.ProgressBar +import ffc.android.layoutInflater import ffc.android.onClick import ffc.app.MainActivity import ffc.app.R @@ -18,6 +20,7 @@ class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) private val fab = actvity.find(R.id.addLocationButton) private val progress = actvity.find(R.id.progress) + val peek = actvity.find(R.id.mapInfoPeek) private val behavior = BottomSheetBehavior.from(actvity.find(R.id.bottom_sheet))!! var currentInfo: GeoMapsInfo = NORMAL @@ -35,9 +38,13 @@ class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) progress.progress = (it * 100.0).toInt() if (it == 1.0) { progress.animate().scaleX(0f).setDuration(150).start() + peek.removeAllViews() + peek.addView(newInfo.getLegendView()) } } progress.animate().scaleX(1f).setDuration(50).setStartDelay(300).start() + peek.removeAllViews() + peek.addView(loadingPeek) } behavior.state = BottomSheetBehavior.STATE_COLLAPSED } @@ -66,6 +73,18 @@ class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) behavior.state = BottomSheetBehavior.STATE_COLLAPSED } } + + fun GeoMapsInfo.getLegendView(): View { + val layoutId = when (this) { + Chronic -> R.layout.maps_info_chronic_peek + else -> R.layout.maps_info_chronic_peek + } + return peek.layoutInflater.inflate(layoutId, peek, false) + } + + val loadingPeek: View by lazy { + peek.layoutInflater.inflate(R.layout.maps_info_peek_loading, peek, false) + } } enum class GeoMapsInfo { diff --git a/ffc/src/main/res/layout/activity_main_content.xml b/ffc/src/main/res/layout/activity_main_content.xml index f0945191..d2327d6b 100644 --- a/ffc/src/main/res/layout/activity_main_content.xml +++ b/ffc/src/main/res/layout/activity_main_content.xml @@ -69,7 +69,7 @@ tools:text="version 4.0.0-10-6167342-photo-dirty" /> - + + + + + + + + + + + + + diff --git a/ffc/src/main/res/layout/maps_info_peek_loading.xml b/ffc/src/main/res/layout/maps_info_peek_loading.xml new file mode 100644 index 00000000..cf46ddda --- /dev/null +++ b/ffc/src/main/res/layout/maps_info_peek_loading.xml @@ -0,0 +1,10 @@ + + diff --git a/ffc/src/main/res/layout/activity_main_sheet.xml b/ffc/src/main/res/layout/maps_info_sheet.xml similarity index 86% rename from ffc/src/main/res/layout/activity_main_sheet.xml rename to ffc/src/main/res/layout/maps_info_sheet.xml index b6ad1b4a..dc2a77c0 100644 --- a/ffc/src/main/res/layout/activity_main_sheet.xml +++ b/ffc/src/main/res/layout/maps_info_sheet.xml @@ -12,15 +12,22 @@ app:cardCornerRadius="12dp" app:cardElevation="12dp" app:behavior_hideable="true" - app:behavior_peekHeight="68dp" + app:behavior_peekHeight="@dimen/map_info_sheet_peek" app:layout_behavior="android.support.design.widget.BottomSheetBehavior" > - + + + - - - - + diff --git a/ffc/src/main/res/values/dimens.xml b/ffc/src/main/res/values/dimens.xml index 93cf56f8..c77712af 100644 --- a/ffc/src/main/res/values/dimens.xml +++ b/ffc/src/main/res/values/dimens.xml @@ -36,4 +36,5 @@ 10dp 16dp 24dp + 72dp From c78c788d650937dc8a2b08ad3573bca617cb4e73 Mon Sep 17 00:00:00 2001 From: Piruin Panichphol Date: Sun, 3 Mar 2019 19:37:39 +0700 Subject: [PATCH 05/10] Add elder info legend --- ffc/src/main/kotlin/ffc/android/Color.kt | 9 +++ ffc/src/main/kotlin/ffc/android/TextView.kt | 44 +++++++--- .../ffc/app/location/GeoMapsInfoSheet.kt | 31 +++++-- .../kotlin/ffc/app/location/LegendView.kt | 81 +++++++++++++++++++ ...nic_peek.xml => maps_info_legend_peek.xml} | 59 +++----------- ffc/src/main/res/layout/maps_info_sheet.xml | 19 +++-- ffc/src/main/res/values/strings.xml | 5 ++ 7 files changed, 179 insertions(+), 69 deletions(-) create mode 100644 ffc/src/main/kotlin/ffc/android/Color.kt create mode 100644 ffc/src/main/kotlin/ffc/app/location/LegendView.kt rename ffc/src/main/res/layout/{maps_info_chronic_peek.xml => maps_info_legend_peek.xml} (55%) diff --git a/ffc/src/main/kotlin/ffc/android/Color.kt b/ffc/src/main/kotlin/ffc/android/Color.kt new file mode 100644 index 00000000..5f9b0ead --- /dev/null +++ b/ffc/src/main/kotlin/ffc/android/Color.kt @@ -0,0 +1,9 @@ +package ffc.android + +import android.content.Context +import android.support.annotation.ColorRes +import android.support.v4.content.ContextCompat +import android.view.View + +fun Context.color(@ColorRes resId: Int) = ContextCompat.getColor(this, resId) +fun View.color(@ColorRes resId: Int) = ContextCompat.getColor(context, resId) diff --git a/ffc/src/main/kotlin/ffc/android/TextView.kt b/ffc/src/main/kotlin/ffc/android/TextView.kt index 50d018b9..3b339576 100644 --- a/ffc/src/main/kotlin/ffc/android/TextView.kt +++ b/ffc/src/main/kotlin/ffc/android/TextView.kt @@ -1,18 +1,26 @@ -/* - * Copyright (c) 2019 NECTEC - * National Electronics and Computer Technology Center, Thailand +/** + * MIT License * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2018 Piruin Panichphol * - * http://www.apache.org/licenses/LICENSE-2.0 + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ @file:Suppress("DEPRECATION") @@ -22,6 +30,8 @@ package ffc.android import android.graphics.drawable.Drawable import android.text.Editable import android.text.TextWatcher +import android.os.Build.VERSION +import android.os.Build.VERSION_CODES import android.widget.TextView fun TextView.getDouble(default: Double? = null): Double? { @@ -69,6 +79,16 @@ private fun TextView.compoundDrawablesRelativeWithIntrinsicBounds( setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom) } +var TextView.textAppearance: Int + get() = throw IllegalAccessException("you can't get textAppearance ") + set(textAppearance) { + if (VERSION.SDK_INT >= VERSION_CODES.M) { + setTextAppearance(textAppearance) + } else { + setTextAppearance(context, textAppearance) + } + } + class TextWatcherDsl : TextWatcher { private var afterChanged: ((Editable?) -> Unit)? = null private var beforeChanged: ((s: CharSequence?, start: Int, count: Int, after: Int) -> Unit)? = null diff --git a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt index fe3b8a56..cc4fcf0c 100644 --- a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt +++ b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt @@ -6,7 +6,9 @@ import android.support.design.widget.FloatingActionButton import android.view.View import android.view.View.OnClickListener import android.view.ViewGroup +import android.widget.ImageView import android.widget.ProgressBar +import ffc.android.drawable import ffc.android.layoutInflater import ffc.android.onClick import ffc.app.MainActivity @@ -23,7 +25,7 @@ class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) val peek = actvity.find(R.id.mapInfoPeek) private val behavior = BottomSheetBehavior.from(actvity.find(R.id.bottom_sheet))!! - var currentInfo: GeoMapsInfo = NORMAL + var currentInfo: GeoMapsInfo = Chronic val onClick = OnClickListener { view -> val newInfo = when (view.id) { @@ -72,14 +74,33 @@ class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) fab.onClick { behavior.state = BottomSheetBehavior.STATE_COLLAPSED } + + peek.addView(currentInfo.getLegendView()) } fun GeoMapsInfo.getLegendView(): View { - val layoutId = when (this) { - Chronic -> R.layout.maps_info_chronic_peek - else -> R.layout.maps_info_chronic_peek + val view = peek.layoutInflater.inflate(R.layout.maps_info_legend_peek, peek, false) + val legend = view.find(R.id.mapInfoLegend) + val icon = view.find(R.id.mapsInfoIcon) + icon.onClick { behavior.state = BottomSheetBehavior.STATE_EXPANDED } + when (this) { + ELDER -> { + legend.setLegend( + R.color.colorAccentLegacy to R.string.elder_socialist, + R.color.yellow_500 to R.string.elder_home, + R.color.red_500 to R.string.elder_immobilised + ) + icon.setImageDrawable(view.drawable(R.drawable.ic_elder_couple_color_24dp)) + } + Chronic -> { + legend.setLegend( + R.color.colorAccentLegacy to R.string.normal, + R.color.red_500 to R.string.chronic + ) + icon.setImageDrawable(view.drawable(R.drawable.ic_heart_cvd_color_24dp)) + } } - return peek.layoutInflater.inflate(layoutId, peek, false) + return view } val loadingPeek: View by lazy { diff --git a/ffc/src/main/kotlin/ffc/app/location/LegendView.kt b/ffc/src/main/kotlin/ffc/app/location/LegendView.kt new file mode 100644 index 00000000..f97d3d90 --- /dev/null +++ b/ffc/src/main/kotlin/ffc/app/location/LegendView.kt @@ -0,0 +1,81 @@ +package ffc.app.location + +import android.content.Context +import android.support.annotation.ColorRes +import android.support.annotation.StringRes +import android.util.AttributeSet +import android.view.Gravity +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import ffc.android.color +import ffc.app.R +import org.jetbrains.anko.dip + +class LegendView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : LinearLayout(context, attrs, defStyleAttr) { + + init { + orientation = LinearLayout.HORIZONTAL + } + + fun setLegend(vararg colorTextPair: Pair) { + removeAllViews() + val layoutParams = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f).apply { + gravity = Gravity.CENTER_VERTICAL + } + colorTextPair.forEach { + val item = LegendItem(context).apply { + colorRes = it.first + textRes = it.second + } + addView(item, layoutParams) + } + } +} + +class LegendItem @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = R.style.AppTheme +) : LinearLayout(context, attrs, defStyleAttr) { + + val colorView = ImageView(context, attrs, defStyleAttr) + val textView = TextView(context, attrs, defStyleAttr) + + var colorRes: Int = -1 + set(@ColorRes value) { + field = value + colorView.setBackgroundColor(color(value)) + } + + var textRes: Int = -1 + set(@StringRes value) { + field = value + textView.setText(value) + } + + init { + orientation = LinearLayout.VERTICAL + + colorView.setBackgroundColor(color(R.color.colorAccent)) + textView.apply { + //textAppearance = android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Body1 + textAlignment = TextView.TEXT_ALIGNMENT_CENTER + } + + addView(colorView, LayoutParams(LayoutParams.MATCH_PARENT, dip(12))) + addView(textView, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT).apply { + topMargin = dip(4) + }) + + if (isInEditMode) { + textRes = R.string.app_name + colorRes = R.color.colorAccent + } + } +} + diff --git a/ffc/src/main/res/layout/maps_info_chronic_peek.xml b/ffc/src/main/res/layout/maps_info_legend_peek.xml similarity index 55% rename from ffc/src/main/res/layout/maps_info_chronic_peek.xml rename to ffc/src/main/res/layout/maps_info_legend_peek.xml index 9df1e0b9..cca797c9 100644 --- a/ffc/src/main/res/layout/maps_info_chronic_peek.xml +++ b/ffc/src/main/res/layout/maps_info_legend_peek.xml @@ -28,63 +28,30 @@ android:orientation="vertical" app:layout_constraintGuide_percent="0.5" /> - - - - + diff --git a/ffc/src/main/res/layout/maps_info_sheet.xml b/ffc/src/main/res/layout/maps_info_sheet.xml index dc2a77c0..1a59cccb 100644 --- a/ffc/src/main/res/layout/maps_info_sheet.xml +++ b/ffc/src/main/res/layout/maps_info_sheet.xml @@ -42,31 +42,38 @@ + + + + diff --git a/ffc/src/main/res/values/strings.xml b/ffc/src/main/res/values/strings.xml index f9bb82ad..d26ad25c 100644 --- a/ffc/src/main/res/values/strings.xml +++ b/ffc/src/main/res/values/strings.xml @@ -128,4 +128,9 @@ ลิขสิทธิ์ การมีส่วนร่วม กรุณาอ่านและทำความเข้าใจ + ติดสังคม + ติดบ้าน + ติดเตียง + ปกติ + เรื้อรัง From 2cd790e0fd2820470554bf0695f778e67d1384b5 Mon Sep 17 00:00:00 2001 From: Piruin Panichphol Date: Sun, 3 Mar 2019 20:17:24 +0700 Subject: [PATCH 06/10] update UI --- ffc/src/main/kotlin/ffc/app/MainActivity.kt | 2 - .../res/drawable/ic_layers_black_24dp.xml | 9 ++++ .../main/res/layout/activity_main_content.xml | 14 ++----- ffc/src/main/res/layout/maps_info_sheet.xml | 42 ++++++++++--------- ffc/src/main/res/values/strings.xml | 2 +- 5 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 ffc/src/main/res/drawable/ic_layers_black_24dp.xml diff --git a/ffc/src/main/kotlin/ffc/app/MainActivity.kt b/ffc/src/main/kotlin/ffc/app/MainActivity.kt index 26102164..897fabc6 100644 --- a/ffc/src/main/kotlin/ffc/app/MainActivity.kt +++ b/ffc/src/main/kotlin/ffc/app/MainActivity.kt @@ -47,7 +47,6 @@ import kotlinx.android.synthetic.main.activity_main.navView import kotlinx.android.synthetic.main.activity_main_content.addLocationButton import kotlinx.android.synthetic.main.activity_main_content.searchButton import kotlinx.android.synthetic.main.activity_main_content.toolbar -import kotlinx.android.synthetic.main.activity_main_content.versionView import org.jetbrains.anko.browse import org.jetbrains.anko.dimen import org.jetbrains.anko.find @@ -76,7 +75,6 @@ class MainActivity : FamilyFolderActivity(), NavigationView.OnNavigationItemSele } setupNavigationDrawer() - versionView.text = BuildConfig.VERSION_NAME with(geoMapsFragment) { setPaddingTop(dimen(R.dimen.maps_padding_top)) } supportFragmentManager diff --git a/ffc/src/main/res/drawable/ic_layers_black_24dp.xml b/ffc/src/main/res/drawable/ic_layers_black_24dp.xml new file mode 100644 index 00000000..2de43d21 --- /dev/null +++ b/ffc/src/main/res/drawable/ic_layers_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/ffc/src/main/res/layout/activity_main_content.xml b/ffc/src/main/res/layout/activity_main_content.xml index d2327d6b..969f21b1 100644 --- a/ffc/src/main/res/layout/activity_main_content.xml +++ b/ffc/src/main/res/layout/activity_main_content.xml @@ -60,14 +60,6 @@ - - @@ -75,13 +67,13 @@ android:id="@+id/addLocationButton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" - android:src="@drawable/ic_add_location_black_24dp" + android:src="@drawable/ic_layers_black_24dp" android:tint="@color/white" app:layout_anchor="@id/bottom_sheet" app:layout_anchorGravity="top|end" android:visibility="gone" - app:fabSize="normal" /> + app:fabSize="mini" + /> diff --git a/ffc/src/main/res/layout/maps_info_sheet.xml b/ffc/src/main/res/layout/maps_info_sheet.xml index 1a59cccb..93c7ce7e 100644 --- a/ffc/src/main/res/layout/maps_info_sheet.xml +++ b/ffc/src/main/res/layout/maps_info_sheet.xml @@ -2,17 +2,17 @@ @@ -29,16 +29,24 @@ + + + - - - - - - diff --git a/ffc/src/main/res/values/strings.xml b/ffc/src/main/res/values/strings.xml index d26ad25c..384ad064 100644 --- a/ffc/src/main/res/values/strings.xml +++ b/ffc/src/main/res/values/strings.xml @@ -132,5 +132,5 @@ ติดบ้าน ติดเตียง ปกติ - เรื้อรัง + โรคเรื้อรัง From f688da02ec194afc9623f4600d5747b86b9ef452 Mon Sep 17 00:00:00 2001 From: Piruin Panichphol Date: Sun, 3 Mar 2019 21:10:43 +0700 Subject: [PATCH 07/10] Add disability map info --- .../ffc/app/location/GeoMapsFragment.kt | 28 ++++++++++++- .../ffc/app/location/GeoMapsInfoSheet.kt | 10 +++++ .../drawable/ic_marker_home_purple_24dp.xml | 13 +++++++ .../res/drawable/ic_wheelchair_color_24dp.xml | 39 +++++++++++++++++++ ffc/src/main/res/layout/maps_info_sheet.xml | 10 +++++ ffc/src/main/res/values/strings.xml | 1 + 6 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 ffc/src/main/res/drawable/ic_marker_home_purple_24dp.xml create mode 100644 ffc/src/main/res/drawable/ic_wheelchair_color_24dp.xml diff --git a/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt b/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt index deb90877..3bac37de 100644 --- a/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt +++ b/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt @@ -23,6 +23,7 @@ import android.arch.lifecycle.ViewModel import android.content.Context import android.content.Intent import android.os.Bundle +import android.support.annotation.ColorInt import android.support.annotation.DrawableRes import android.support.design.widget.FloatingActionButton import com.google.android.gms.maps.GoogleMap @@ -35,11 +36,13 @@ import ffc.android.drawable import ffc.android.observe import ffc.android.rawAs import ffc.android.sceneTransition +import ffc.android.tint import ffc.android.toBitmap import ffc.android.viewModel import ffc.app.R import ffc.app.dev import ffc.app.familyFolderActivity +import ffc.app.location.GeoMapsInfo.Disability import ffc.app.location.GeoMapsInfo.ELDER import ffc.app.util.alert.handle import ffc.app.util.forEachChunk @@ -143,6 +146,7 @@ class GeoMapsFragment : BaseMapsFragment() { fun showInfo(info: GeoMapsInfo, onProgress: (Double) -> Unit) { markerStyles = when (info) { ELDER -> ElderMarkerStyle(context!!) + Disability -> DisabilityMarkerStyle(context!!) else -> ChronicMarkerStyles(context!!) } @@ -175,8 +179,11 @@ class GeoMapsFragment : BaseMapsFragment() { val context: Context - fun bitmapOf(@DrawableRes resId: Int): BitmapDescriptor = - BitmapDescriptorFactory.fromBitmap(context.drawable(resId).toBitmap()) + fun bitmapOf(@DrawableRes resId: Int, @ColorInt color: Int? = null): BitmapDescriptor { + val drawable = context.drawable(resId) + color?.let { drawable.tint(color) } + return BitmapDescriptorFactory.fromBitmap(drawable.toBitmap()) + } fun pointStyleOf(it: GeoJsonFeature): GeoJsonPointStyle } @@ -216,5 +223,22 @@ class GeoMapsFragment : BaseMapsFragment() { } } } + + class DisabilityMarkerStyle(override val context: Context) : MarkerStyles { + + private val notElderIcon by lazy { bitmapOf(R.drawable.ic_marker_home_grey_24dp) } + private val disabilityIcon by lazy { bitmapOf(R.drawable.ic_marker_home_purple_24dp) } + + override fun pointStyleOf(it: GeoJsonFeature): GeoJsonPointStyle { + return GeoJsonPointStyle().apply { + val md5 = it.getProperty("no").md5().toLowerCase() + icon = when (md5[0]) { + '1' -> disabilityIcon + else -> notElderIcon + } + title = md5 + } + } + } } diff --git a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt index cc4fcf0c..40ca602d 100644 --- a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt +++ b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt @@ -14,6 +14,7 @@ import ffc.android.onClick import ffc.app.MainActivity import ffc.app.R import ffc.app.location.GeoMapsInfo.Chronic +import ffc.app.location.GeoMapsInfo.Disability import ffc.app.location.GeoMapsInfo.ELDER import ffc.app.location.GeoMapsInfo.NORMAL import org.jetbrains.anko.find @@ -31,6 +32,7 @@ class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) val newInfo = when (view.id) { R.id.elderMapInfo -> ELDER R.id.cvdMapInfo -> Chronic + R.id.disabilityMapInfo -> Disability else -> NORMAL } if (newInfo != currentInfo) { @@ -67,6 +69,7 @@ class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) }) actvity.find(R.id.elderMapInfo).setOnClickListener(onClick) actvity.find(R.id.cvdMapInfo).setOnClickListener(onClick) + actvity.find(R.id.disabilityMapInfo).setOnClickListener(onClick) progress.max = 100 progress.animate().scaleX(0f).setDuration(0).start() @@ -99,6 +102,13 @@ class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) ) icon.setImageDrawable(view.drawable(R.drawable.ic_heart_cvd_color_24dp)) } + Disability -> { + legend.setLegend( + R.color.grey_300 to R.string.normal, + R.color.purple_300 to R.string.disability + ) + icon.setImageDrawable(view.drawable(R.drawable.ic_wheelchair_color_24dp)) + } } return view } diff --git a/ffc/src/main/res/drawable/ic_marker_home_purple_24dp.xml b/ffc/src/main/res/drawable/ic_marker_home_purple_24dp.xml new file mode 100644 index 00000000..afe6889e --- /dev/null +++ b/ffc/src/main/res/drawable/ic_marker_home_purple_24dp.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/ffc/src/main/res/drawable/ic_wheelchair_color_24dp.xml b/ffc/src/main/res/drawable/ic_wheelchair_color_24dp.xml new file mode 100644 index 00000000..d6eacc45 --- /dev/null +++ b/ffc/src/main/res/drawable/ic_wheelchair_color_24dp.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + diff --git a/ffc/src/main/res/layout/maps_info_sheet.xml b/ffc/src/main/res/layout/maps_info_sheet.xml index 93c7ce7e..0ea0e61e 100644 --- a/ffc/src/main/res/layout/maps_info_sheet.xml +++ b/ffc/src/main/res/layout/maps_info_sheet.xml @@ -78,6 +78,16 @@ app:layout_gravity="fill_horizontal" /> + + diff --git a/ffc/src/main/res/values/strings.xml b/ffc/src/main/res/values/strings.xml index 384ad064..94f9e73e 100644 --- a/ffc/src/main/res/values/strings.xml +++ b/ffc/src/main/res/values/strings.xml @@ -133,4 +133,5 @@ ติดเตียง ปกติ โรคเรื้อรัง + พิการ From 88022c04e2f42a5fb376b5c7f7891ff2fd2fd7bd Mon Sep 17 00:00:00 2001 From: Piruin Panichphol Date: Mon, 4 Mar 2019 18:39:36 +0700 Subject: [PATCH 08/10] fix format --- .../ffc/app/location/BaseMapsFragment.kt | 17 +++++++++++++++++ .../kotlin/ffc/app/location/GeoMapsFragment.kt | 4 ---- .../main/kotlin/ffc/app/location/LegendView.kt | 18 +++++++++++++++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt b/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt index 88057991..3bf831ca 100644 --- a/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt +++ b/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2019 NECTEC + * National Electronics and Computer Technology Center, Thailand + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package ffc.app.location import android.os.Bundle diff --git a/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt b/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt index 3bac37de..000613d2 100644 --- a/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt +++ b/ffc/src/main/kotlin/ffc/app/location/GeoMapsFragment.kt @@ -97,8 +97,6 @@ class GeoMapsFragment : BaseMapsFragment() { } } - - override fun onMapReady(googleMap: GoogleMap?) { super.onMapReady(googleMap) // viewModel.geojson.value = doAsyncResult { preference.geojsonCache }.get() @@ -167,7 +165,6 @@ class GeoMapsFragment : BaseMapsFragment() { } } - class GeoViewModel : ViewModel() { val geojson = MutableLiveData>() val json = MutableLiveData() @@ -241,4 +238,3 @@ class GeoMapsFragment : BaseMapsFragment() { } } } - diff --git a/ffc/src/main/kotlin/ffc/app/location/LegendView.kt b/ffc/src/main/kotlin/ffc/app/location/LegendView.kt index f97d3d90..ebc4e065 100644 --- a/ffc/src/main/kotlin/ffc/app/location/LegendView.kt +++ b/ffc/src/main/kotlin/ffc/app/location/LegendView.kt @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2019 NECTEC + * National Electronics and Computer Technology Center, Thailand + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package ffc.app.location import android.content.Context @@ -78,4 +95,3 @@ class LegendItem @JvmOverloads constructor( } } } - From 5a18836cf5d3384bf7a66a4e825c7f3ed54125b3 Mon Sep 17 00:00:00 2001 From: Piruin Panichphol Date: Fri, 18 Oct 2019 13:56:34 +0700 Subject: [PATCH 09/10] Fix maps error on first-time start --- ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt b/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt index 3bf831ca..07f96637 100644 --- a/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt +++ b/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt @@ -33,7 +33,7 @@ open class BaseMapsFragment : MarloFragment() { override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) - setStartLocation(preference.lastCameraPosition!!) + preference.lastCameraPosition?.let { setStartLocation(it) } viewFinder.gone() hideToolsMenu() } From 16a776dbf1e70d837e582c780a8ca8976fe36cc7 Mon Sep 17 00:00:00 2001 From: Piruin Panichphol Date: Fri, 18 Oct 2019 13:58:23 +0700 Subject: [PATCH 10/10] Fix ktlint format --- .../ffc/app/location/BaseMapsFragment.kt | 7 +++++-- .../ffc/app/location/GeoMapsInfoSheet.kt | 19 ++++++++++++++++- .../main/res/layout/activity_main_content.xml | 19 ++++++++++++----- ffc/src/main/res/layout/maps_info_sheet.xml | 21 ++++++++++++++++++- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt b/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt index 07f96637..b3d4b95b 100644 --- a/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt +++ b/ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt @@ -47,8 +47,11 @@ open class BaseMapsFragment : MarloFragment() { } } - override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, - grantResults: IntArray) { + override fun onRequestPermissionsResult( + requestCode: Int, + permissions: Array, + grantResults: IntArray + ) { activity!!.handlePermissionsResult(requestCode, permissions, grantResults) } diff --git a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt index 40ca602d..2ce0e94a 100644 --- a/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt +++ b/ffc/src/main/kotlin/ffc/app/location/GeoMapsInfoSheet.kt @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2019 NECTEC + * National Electronics and Computer Technology Center, Thailand + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package ffc.app.location import android.support.design.widget.BottomSheetBehavior @@ -21,7 +38,7 @@ import org.jetbrains.anko.find class GeoMapsInfoSheet(actvity: MainActivity, geoMapsFragment: GeoMapsFragment) { - private val fab = actvity.find(R.id.addLocationButton) + private val fab = actvity.find(R.id.mapLayoutOption) private val progress = actvity.find(R.id.progress) val peek = actvity.find(R.id.mapInfoPeek) private val behavior = BottomSheetBehavior.from(actvity.find(R.id.bottom_sheet))!! diff --git a/ffc/src/main/res/layout/activity_main_content.xml b/ffc/src/main/res/layout/activity_main_content.xml index 969f21b1..753e4287 100644 --- a/ffc/src/main/res/layout/activity_main_content.xml +++ b/ffc/src/main/res/layout/activity_main_content.xml @@ -1,5 +1,5 @@ + -