Merge branch 'master' of ssh://github.com/osmandapp/Osmand into CoordinateInputImprovements

This commit is contained in:
Chumva 2018-06-19 17:54:17 +03:00
commit caa581e855
22 changed files with 125 additions and 32 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,020 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,020 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,018 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,018 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,023 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,023 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -1,23 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="0dp"
android:layout_weight="1">
<android.support.v7.widget.RecyclerView
android:id="@+id/groups_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:scrollbars="vertical" />
<net.osmand.telegram.views.LockableViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<android.support.v7.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:scaleType="fitXY"
android:src="?attr/bottom_nav_shadow" />
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
@ -30,5 +45,3 @@
tools:visibility="visible" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

View file

@ -5,5 +5,6 @@
<attr name="icon_color" format="reference" />
<attr name="ctrl_active_color" format="reference" />
<attr name="ctrl_color" format="reference" />
<attr name="bottom_nav_shadow" format="reference" />
</declare-styleable>
</resources>

View file

@ -19,6 +19,8 @@
<item name="icon_color">@color/icon_color_light</item>
<item name="ctrl_active_color">@color/ctrl_active_color_light</item>
<item name="ctrl_color">@color/ctrl_color_light</item>
<item name="bottom_nav_shadow">@drawable/bg_bottom_bar_shadow_with_line_day</item>
</style>
<style name="AppTheme.NoActionbar">

View file

@ -340,6 +340,10 @@ class MainActivity : AppCompatActivity(), TelegramListener {
if (settings.hasAnyChatToShareLocation()) {
app.shareLocationHelper.startSharingLocation()
}
} else {
settings.stopSharingLocationToChats()
app.shareLocationHelper.stopSharingLocation()
updateChatsList()
}
if (settings.hasAnyChatToShowOnMap() && osmandHelper.isOsmandNotInstalled()) {
showOsmandMissingDialog()

View file

@ -127,6 +127,10 @@ class TelegramApplication : Application(), OsmandHelperListener {
telegramService?.stopIfNeeded(this, TelegramService.USED_BY_MY_LOCATION)
}
fun forceUpdateMyLocation() {
telegramService?.forceLocationUpdate()
}
fun startUserLocationService() {
startTelegramService(TelegramService.USED_BY_USERS_LOCATIONS)
}

View file

@ -1,5 +1,6 @@
package net.osmand.telegram
import android.annotation.SuppressLint
import android.app.AlarmManager
import android.app.PendingIntent
import android.app.Service
@ -14,7 +15,9 @@ import android.widget.Toast
import net.osmand.PlatformUtil
import net.osmand.telegram.helpers.TelegramHelper.TelegramIncomingMessagesListener
import net.osmand.telegram.notifications.TelegramNotification.NotificationType
import net.osmand.telegram.utils.AndroidUtils
import org.drinkless.td.libcore.telegram.TdApi
import java.util.ArrayList
import java.util.concurrent.Executors
class TelegramService : Service(), LocationListener, TelegramIncomingMessagesListener {
@ -127,7 +130,15 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
stopForeground(java.lang.Boolean.TRUE)
}
fun forceLocationUpdate() {
val location = getFirstTimeRunDefaultLocation()
app().shareLocationHelper.updateLocation(location)
}
private fun initLocationUpdates() {
val firstLocation = getFirstTimeRunDefaultLocation()
app().shareLocationHelper.updateLocation(firstLocation)
// requesting
if (isContinuous()) {
// request location updates
@ -146,6 +157,32 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
}
}
@SuppressLint("MissingPermission")
private fun getFirstTimeRunDefaultLocation(): net.osmand.Location? {
val app = app()
if (!AndroidUtils.isLocationPermissionAvailable(app)) {
return null
}
val service = app.getSystemService(Context.LOCATION_SERVICE) as LocationManager
val ps = service.getProviders(true) ?: return null
val providers = ArrayList(ps)
// note, passive provider is from API_LEVEL 8 but it is a constant, we can check for it.
// constant should not be changed in future
val passiveFirst = providers.indexOf("passive") // LocationManager.PASSIVE_PROVIDER
// put passive provider to first place
if (passiveFirst > -1) {
providers.add(0, providers.removeAt(passiveFirst))
}
// find location
for (provider in providers) {
val location = convertLocation(service.getLastKnownLocation(provider))
if (location != null) {
return location
}
}
return null
}
private fun setupAlarm() {
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
pendingIntent = PendingIntent.getBroadcast(this, 0, Intent(this, OnTelegramServiceAlarmReceiver::class.java), PendingIntent.FLAG_UPDATE_CURRENT)

View file

@ -72,6 +72,10 @@ class TelegramSettings(private val app: TelegramApplication) {
this.shareLocationChats = shareLocationChats.toHashSet()
}
fun stopSharingLocationToChats() {
this.shareLocationChats = emptySet()
}
fun showChatOnMap(chatTitle: String, show: Boolean) {
val showOnMapChats = showOnMapChats.toMutableList()
if (show) {

View file

@ -58,6 +58,8 @@ class ShareLocationHelper(private val app: TelegramApplication) {
app.startMyLocationService()
refreshNotification()
} else {
app.forceUpdateMyLocation()
}
}

View file

@ -0,0 +1,26 @@
package net.osmand.telegram.views
import android.content.Context
import android.support.v4.view.ViewPager
import android.util.AttributeSet
import android.view.MotionEvent
class LockableViewPager : ViewPager {
var swipeLocked: Boolean = false
constructor(context: Context) : super(context) {}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
override fun onTouchEvent(event: MotionEvent): Boolean {
return !swipeLocked && super.onTouchEvent(event)
}
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
return !swipeLocked && super.onInterceptTouchEvent(event)
}
override fun canScrollHorizontally(direction: Int): Boolean {
return !swipeLocked && super.canScrollHorizontally(direction)
}
}

View file

@ -9,8 +9,8 @@ android {
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
}

View file

@ -20,8 +20,8 @@ android {
}
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
minSdkVersion 15
targetSdkVersion 27
}
lintOptions {

View file

@ -21,8 +21,8 @@ android {
}
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
minSdkVersion 15
targetSdkVersion 27
}
lintOptions {

View file

@ -21,8 +21,8 @@ android {
}
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
minSdkVersion 15
targetSdkVersion 27
}
lintOptions {

View file

@ -21,8 +21,8 @@ android {
}
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
minSdkVersion 15
targetSdkVersion 27
}
lintOptions {