mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 12:39:58 +01:00
improve design for locationpicker screen
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
e8a9fa6303
commit
d5face5941
@ -3,15 +3,19 @@ package com.nextcloud.talk.controllers
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ImageButton
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.cardview.widget.CardView
|
||||
import androidx.core.content.PermissionChecker
|
||||
import androidx.preference.PreferenceManager
|
||||
import autodagger.AutoInjector
|
||||
@ -30,6 +34,10 @@ import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.osmdroid.config.Configuration.getInstance
|
||||
import org.osmdroid.events.DelayedMapListener
|
||||
import org.osmdroid.events.MapListener
|
||||
import org.osmdroid.events.ScrollEvent
|
||||
import org.osmdroid.events.ZoomEvent
|
||||
import org.osmdroid.tileprovider.tilesource.TileSourceFactory
|
||||
import org.osmdroid.util.GeoPoint
|
||||
import org.osmdroid.views.MapView
|
||||
@ -61,15 +69,27 @@ class LocationController(args: Bundle) : BaseController(args) {
|
||||
|
||||
@BindView(R.id.ic_center_map)
|
||||
@JvmField
|
||||
var btCenterMap: ImageButton? = null
|
||||
var btCenterMap: CardView? = null
|
||||
|
||||
@BindView(R.id.btn_select_location)
|
||||
@BindView(R.id.share_location)
|
||||
@JvmField
|
||||
var btnSelectLocation: Button? = null
|
||||
var shareLocation: LinearLayout? = null
|
||||
|
||||
var roomToken : String?
|
||||
@BindView(R.id.gps_accuracy)
|
||||
@JvmField
|
||||
var gpsAccuracy: TextView? = null
|
||||
|
||||
@BindView(R.id.share_location_description)
|
||||
@JvmField
|
||||
var shareLocationDescription: TextView? = null
|
||||
|
||||
var roomToken: String?
|
||||
|
||||
var moveToCurrentLocationWasClicked: Boolean = true
|
||||
var readyToShareLocation: Boolean = false
|
||||
|
||||
init {
|
||||
setHasOptionsMenu(true)
|
||||
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
||||
getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context))
|
||||
|
||||
@ -82,46 +102,44 @@ class LocationController(args: Bundle) : BaseController(args) {
|
||||
|
||||
override fun onAttach(view: View) {
|
||||
super.onAttach(view)
|
||||
drawMap()
|
||||
initMap()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
inflater.inflate(R.menu.menu_conversation_plus_filter, menu)
|
||||
// searchItem = menu.findItem(R.id.action_search)
|
||||
// initSearchView()
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
super.onPrepareOptionsMenu(menu)
|
||||
Log.d(TAG, "onPrepareOptionsMenu")
|
||||
hideSearchBar()
|
||||
actionBar.setIcon(ColorDrawable(resources!!.getColor(android.R.color.transparent)));
|
||||
actionBar.title = "Share location"
|
||||
|
||||
// searchView = MenuItemCompat.getActionView(searchItem) as SearchView
|
||||
// showShareToScreen = !shareToScreenWasShown && hasActivityActionSendIntent()
|
||||
// if (showShareToScreen) {
|
||||
// hideSearchBar()
|
||||
// actionBar.setTitle(R.string.send_to_three_dots)
|
||||
// }
|
||||
}
|
||||
|
||||
override fun onViewBound(view: View) {
|
||||
btnSelectLocation?.setOnClickListener {
|
||||
val selectedLat: Double? = map?.mapCenter?.latitude
|
||||
val selectedLon: Double? = map?.mapCenter?.longitude
|
||||
|
||||
ncApi.sendLocation(
|
||||
ApiUtils.getCredentials(userUtils.currentUser?.username, userUtils.currentUser?.token),
|
||||
ApiUtils.getUrlToSendLocation(userUtils.currentUser?.baseUrl, roomToken),
|
||||
"geo-location",
|
||||
"geo:$selectedLat,$selectedLon",
|
||||
"{\"type\":\"geo-location\",\"id\":\"geo:$selectedLat,$selectedLon\",\"latitude\":\"$selectedLat\"," +
|
||||
"\"longitude\":\"$selectedLon\",\"name\":\"examplePlace\"}"
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Observer<GenericOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
}
|
||||
|
||||
override fun onNext(t: GenericOverall) {
|
||||
Log.d(TAG, "shared location")
|
||||
router.popCurrentController()
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "error when trying to share location", e)
|
||||
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
|
||||
router.popCurrentController()
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
}
|
||||
})
|
||||
setCurrentLocationDescription()
|
||||
shareLocation?.isClickable = false
|
||||
shareLocation?.setOnClickListener {
|
||||
if(readyToShareLocation){
|
||||
shareLocation()
|
||||
} else {
|
||||
Log.d(TAG, "readyToShareLocation was false while user tried to share location.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun drawMap(){
|
||||
private fun initMap() {
|
||||
if (!isFineLocationPermissionGranted()) {
|
||||
requestFineLocationPermission()
|
||||
}
|
||||
@ -137,7 +155,7 @@ class LocationController(args: Bundle) : BaseController(args) {
|
||||
map?.isTilesScaledToDpi = true
|
||||
|
||||
val locationOverlay = MyLocationNewOverlay(GpsMyLocationProvider(context), map)
|
||||
locationOverlay.enableFollowLocation()
|
||||
// locationOverlay.enableFollowLocation()
|
||||
locationOverlay.enableMyLocation()
|
||||
// locationOverlay.setPersonIcon(
|
||||
// DisplayUtils.getBitmap(ResourcesCompat.getDrawable(resources!!, R.drawable.current_location_circle, null)))
|
||||
@ -147,7 +165,7 @@ class LocationController(args: Bundle) : BaseController(args) {
|
||||
mapController?.setZoom(12.0)
|
||||
|
||||
var myLocation: GeoPoint
|
||||
myLocation = GeoPoint(52.0 , 13.0)
|
||||
myLocation = GeoPoint(52.0, 13.0)
|
||||
|
||||
locationOverlay.runOnFirstFix(Runnable {
|
||||
activity!!.runOnUiThread {
|
||||
@ -158,7 +176,70 @@ class LocationController(args: Bundle) : BaseController(args) {
|
||||
|
||||
btCenterMap?.setOnClickListener(View.OnClickListener {
|
||||
map?.controller?.animateTo(myLocation)
|
||||
setCurrentLocationDescription()
|
||||
moveToCurrentLocationWasClicked = true
|
||||
})
|
||||
|
||||
map?.addMapListener(DelayedMapListener(object : MapListener {
|
||||
override fun onScroll(paramScrollEvent: ScrollEvent): Boolean {
|
||||
if (moveToCurrentLocationWasClicked) {
|
||||
moveToCurrentLocationWasClicked = false
|
||||
} else {
|
||||
shareLocation?.isClickable = true
|
||||
shareLocationDescription?.text = "Share this location"
|
||||
gpsAccuracy?.text = ""
|
||||
}
|
||||
readyToShareLocation = true
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onZoom(event: ZoomEvent): Boolean {
|
||||
return false
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
private fun setCurrentLocationDescription() {
|
||||
shareLocationDescription?.text = "Share current location"
|
||||
gpsAccuracy?.text = "Accuracy: xx m"
|
||||
}
|
||||
|
||||
private fun shareLocation() {
|
||||
val selectedLat: Double? = map?.mapCenter?.latitude
|
||||
val selectedLon: Double? = map?.mapCenter?.longitude
|
||||
val name = ""
|
||||
val objectId = "geo:$selectedLat,$selectedLon"
|
||||
val metaData: String =
|
||||
"{\"type\":\"geo-location\",\"id\":\"geo:$selectedLat,$selectedLon\",\"latitude\":\"$selectedLat\"," +
|
||||
"\"longitude\":\"$selectedLon\",\"name\":\"$name\"}"
|
||||
|
||||
ncApi.sendLocation(
|
||||
ApiUtils.getCredentials(userUtils.currentUser?.username, userUtils.currentUser?.token),
|
||||
ApiUtils.getUrlToSendLocation(userUtils.currentUser?.baseUrl, roomToken),
|
||||
"geo-location",
|
||||
objectId,
|
||||
metaData
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Observer<GenericOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
}
|
||||
|
||||
override fun onNext(t: GenericOverall) {
|
||||
Log.d(TAG, "shared location")
|
||||
router.popCurrentController()
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "error when trying to share location", e)
|
||||
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
|
||||
router.popCurrentController()
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun isFineLocationPermissionGranted(): Boolean {
|
||||
@ -191,7 +272,7 @@ class LocationController(args: Bundle) : BaseController(args) {
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE && grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
drawMap()
|
||||
initMap()
|
||||
} else {
|
||||
Toast.makeText(context, "location permission required!", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
@ -2,9 +2,8 @@
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:fillColor="@color/fontAppbar"
|
||||
android:pathData="M12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM20.94,11c-0.46,-4.17 -3.77,-7.48 -7.94,-7.94L13,1h-2v2.06C6.83,3.52 3.52,6.83 3.06,11L1,11v2h2.06c0.46,4.17 3.77,7.48 7.94,7.94L11,23h2v-2.06c4.17,-0.46 7.48,-3.77 7.94,-7.94L23,13v-2h-2.06zM12,19c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z"/>
|
||||
</vector>
|
||||
|
@ -1,22 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/parent_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp">
|
||||
<SearchView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:queryHint="Search for places">
|
||||
</SearchView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
@ -26,18 +16,25 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/ic_center_map"
|
||||
android:src="@drawable/ic_baseline_gps_fixed_24"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:background="#00ffffff"
|
||||
android:cropToPadding="true"
|
||||
android:contentDescription="go to current location" />
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_margin="5dp"
|
||||
android:elevation="10dp"
|
||||
app:cardCornerRadius="25dp"
|
||||
app:cardBackgroundColor="@color/appbar">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/roundedImageView"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:src="@drawable/ic_baseline_gps_fixed_24"
|
||||
android:layout_gravity="center"
|
||||
/>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<View
|
||||
android:id="@+id/locationpicker_anchor"
|
||||
@ -57,15 +54,40 @@
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/share_location"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp">
|
||||
<Button
|
||||
android:id="@+id/btn_select_location"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Share location">
|
||||
android:layout_height="70dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:height="60dp"
|
||||
android:minWidth="50dp"
|
||||
android:padding="10dp"
|
||||
android:textAlignment="textStart"
|
||||
app:srcCompat="@drawable/ic_baseline_location_on_24">
|
||||
</ImageView>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/share_location_description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center_vertical">
|
||||
</TextView>
|
||||
<TextView
|
||||
android:id="@+id/gps_accuracy"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
|
||||
</Button>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user