improve design for locationpicker screen

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2021-05-31 19:12:51 +02:00 committed by Andy Scherzinger
parent e8a9fa6303
commit d5face5941
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
3 changed files with 175 additions and 73 deletions

View File

@ -3,15 +3,19 @@ package com.nextcloud.talk.controllers
import android.Manifest import android.Manifest
import android.content.Context import android.content.Context
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.graphics.drawable.ColorDrawable
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button import android.widget.LinearLayout
import android.widget.ImageButton import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.cardview.widget.CardView
import androidx.core.content.PermissionChecker import androidx.core.content.PermissionChecker
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import autodagger.AutoInjector import autodagger.AutoInjector
@ -30,6 +34,10 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import org.osmdroid.config.Configuration.getInstance 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.tileprovider.tilesource.TileSourceFactory
import org.osmdroid.util.GeoPoint import org.osmdroid.util.GeoPoint
import org.osmdroid.views.MapView import org.osmdroid.views.MapView
@ -61,15 +69,27 @@ class LocationController(args: Bundle) : BaseController(args) {
@BindView(R.id.ic_center_map) @BindView(R.id.ic_center_map)
@JvmField @JvmField
var btCenterMap: ImageButton? = null var btCenterMap: CardView? = null
@BindView(R.id.btn_select_location) @BindView(R.id.share_location)
@JvmField @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 { init {
setHasOptionsMenu(true)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context)) getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context))
@ -82,46 +102,44 @@ class LocationController(args: Bundle) : BaseController(args) {
override fun onAttach(view: View) { override fun onAttach(view: View) {
super.onAttach(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) { override fun onViewBound(view: View) {
btnSelectLocation?.setOnClickListener { setCurrentLocationDescription()
val selectedLat: Double? = map?.mapCenter?.latitude shareLocation?.isClickable = false
val selectedLon: Double? = map?.mapCenter?.longitude shareLocation?.setOnClickListener {
if(readyToShareLocation){
ncApi.sendLocation( shareLocation()
ApiUtils.getCredentials(userUtils.currentUser?.username, userUtils.currentUser?.token), } else {
ApiUtils.getUrlToSendLocation(userUtils.currentUser?.baseUrl, roomToken), Log.d(TAG, "readyToShareLocation was false while user tried to share location.")
"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() {
}
})
} }
} }
fun drawMap(){ private fun initMap() {
if (!isFineLocationPermissionGranted()) { if (!isFineLocationPermissionGranted()) {
requestFineLocationPermission() requestFineLocationPermission()
} }
@ -137,7 +155,7 @@ class LocationController(args: Bundle) : BaseController(args) {
map?.isTilesScaledToDpi = true map?.isTilesScaledToDpi = true
val locationOverlay = MyLocationNewOverlay(GpsMyLocationProvider(context), map) val locationOverlay = MyLocationNewOverlay(GpsMyLocationProvider(context), map)
locationOverlay.enableFollowLocation() // locationOverlay.enableFollowLocation()
locationOverlay.enableMyLocation() locationOverlay.enableMyLocation()
// locationOverlay.setPersonIcon( // locationOverlay.setPersonIcon(
// DisplayUtils.getBitmap(ResourcesCompat.getDrawable(resources!!, R.drawable.current_location_circle, null))) // 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) mapController?.setZoom(12.0)
var myLocation: GeoPoint var myLocation: GeoPoint
myLocation = GeoPoint(52.0 , 13.0) myLocation = GeoPoint(52.0, 13.0)
locationOverlay.runOnFirstFix(Runnable { locationOverlay.runOnFirstFix(Runnable {
activity!!.runOnUiThread { activity!!.runOnUiThread {
@ -158,7 +176,70 @@ class LocationController(args: Bundle) : BaseController(args) {
btCenterMap?.setOnClickListener(View.OnClickListener { btCenterMap?.setOnClickListener(View.OnClickListener {
map?.controller?.animateTo(myLocation) 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 { 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) { 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) { if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE && grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
drawMap() initMap()
} else { } else {
Toast.makeText(context, "location permission required!", Toast.LENGTH_LONG).show() Toast.makeText(context, "location permission required!", Toast.LENGTH_LONG).show()
} }

View File

@ -2,9 +2,8 @@
android:width="24dp" android:width="24dp"
android:height="24dp" android:height="24dp"
android:viewportWidth="24" android:viewportWidth="24"
android:viewportHeight="24" android:viewportHeight="24">
android:tint="?attr/colorControlNormal">
<path <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"/> 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> </vector>

View File

@ -1,22 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <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:id="@+id/parent_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> 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 <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
@ -26,18 +16,25 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" /> android:layout_height="fill_parent" />
<ImageButton <androidx.cardview.widget.CardView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/ic_center_map" android:id="@+id/ic_center_map"
android:src="@drawable/ic_baseline_gps_fixed_24"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_marginTop="10dp" android:layout_width="50dp"
android:layout_marginEnd="10dp" android:layout_height="50dp"
android:background="#00ffffff" android:layout_margin="5dp"
android:cropToPadding="true" android:elevation="10dp"
android:contentDescription="go to current location" /> 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 <View
android:id="@+id/locationpicker_anchor" android:id="@+id/locationpicker_anchor"
@ -57,15 +54,40 @@
</RelativeLayout> </RelativeLayout>
<LinearLayout <LinearLayout
android:id="@+id/share_location"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="80dp"> android:layout_height="70dp"
<Button android:orientation="horizontal">
android:id="@+id/btn_select_location"
android:layout_width="match_parent" <ImageView
android:layout_height="match_parent" android:layout_width="wrap_content"
android:text="Share location"> 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> </LinearLayout>