Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ffc/src/main/kotlin/ffc/android/Color.kt
Original file line number Diff line number Diff line change
@@ -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)
44 changes: 32 additions & 12 deletions ffc/src/main/kotlin/ffc/android/TextView.kt
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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? {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions ffc/src/main/kotlin/ffc/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,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
Expand Down Expand Up @@ -75,7 +75,6 @@ class MainActivity : FamilyFolderActivity(), NavigationView.OnNavigationItemSele
}

setupNavigationDrawer()
versionView.text = BuildConfig.VERSION_NAME

with(geoMapsFragment) { setPaddingTop(dimen(R.dimen.maps_padding_top)) }
supportFragmentManager
Expand All @@ -87,6 +86,8 @@ class MainActivity : FamilyFolderActivity(), NavigationView.OnNavigationItemSele
observe(viewModel.houseNoLocation) {
if (it == true) addLocationButton.show() else addLocationButton.hide()
}

GeoMapsInfoSheet(this, geoMapsFragment)
}

private fun setupNavigationDrawer() {
Expand Down
81 changes: 81 additions & 0 deletions ffc/src/main/kotlin/ffc/app/location/BaseMapsFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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
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)
preference.lastCameraPosition?.let { setStartLocation(it) }
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<out String>,
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
}
}
Loading