Merge branch 'master' of ssh://github.com/osmandapp/Osmand into CoordinateInputImprovements
After Width: | Height: | Size: 1,020 B |
After Width: | Height: | Size: 1,020 B |
After Width: | Height: | Size: 1,018 B |
After Width: | Height: | Size: 1,018 B |
After Width: | Height: | Size: 1,023 B |
After Width: | Height: | Size: 1,023 B |
After Width: | Height: | Size: 1 KiB |
After Width: | Height: | Size: 1 KiB |
|
@ -1,23 +1,38 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="0dp"
|
||||||
android:orientation="vertical">
|
android:layout_weight="1">
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/groups_view"
|
android:id="@+id/groups_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
|
||||||
android:scrollbars="vertical" />
|
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.support.design.widget.BottomNavigationView
|
||||||
android:id="@+id/bottom_navigation"
|
android:id="@+id/bottom_navigation"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -30,5 +45,3 @@
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
|
|
@ -5,5 +5,6 @@
|
||||||
<attr name="icon_color" format="reference" />
|
<attr name="icon_color" format="reference" />
|
||||||
<attr name="ctrl_active_color" format="reference" />
|
<attr name="ctrl_active_color" format="reference" />
|
||||||
<attr name="ctrl_color" format="reference" />
|
<attr name="ctrl_color" format="reference" />
|
||||||
|
<attr name="bottom_nav_shadow" format="reference" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
|
@ -19,6 +19,8 @@
|
||||||
<item name="icon_color">@color/icon_color_light</item>
|
<item name="icon_color">@color/icon_color_light</item>
|
||||||
<item name="ctrl_active_color">@color/ctrl_active_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="ctrl_color">@color/ctrl_color_light</item>
|
||||||
|
|
||||||
|
<item name="bottom_nav_shadow">@drawable/bg_bottom_bar_shadow_with_line_day</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="AppTheme.NoActionbar">
|
<style name="AppTheme.NoActionbar">
|
||||||
|
|
|
@ -340,6 +340,10 @@ class MainActivity : AppCompatActivity(), TelegramListener {
|
||||||
if (settings.hasAnyChatToShareLocation()) {
|
if (settings.hasAnyChatToShareLocation()) {
|
||||||
app.shareLocationHelper.startSharingLocation()
|
app.shareLocationHelper.startSharingLocation()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
settings.stopSharingLocationToChats()
|
||||||
|
app.shareLocationHelper.stopSharingLocation()
|
||||||
|
updateChatsList()
|
||||||
}
|
}
|
||||||
if (settings.hasAnyChatToShowOnMap() && osmandHelper.isOsmandNotInstalled()) {
|
if (settings.hasAnyChatToShowOnMap() && osmandHelper.isOsmandNotInstalled()) {
|
||||||
showOsmandMissingDialog()
|
showOsmandMissingDialog()
|
||||||
|
|
|
@ -127,6 +127,10 @@ class TelegramApplication : Application(), OsmandHelperListener {
|
||||||
telegramService?.stopIfNeeded(this, TelegramService.USED_BY_MY_LOCATION)
|
telegramService?.stopIfNeeded(this, TelegramService.USED_BY_MY_LOCATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun forceUpdateMyLocation() {
|
||||||
|
telegramService?.forceLocationUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
fun startUserLocationService() {
|
fun startUserLocationService() {
|
||||||
startTelegramService(TelegramService.USED_BY_USERS_LOCATIONS)
|
startTelegramService(TelegramService.USED_BY_USERS_LOCATIONS)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.telegram
|
package net.osmand.telegram
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.AlarmManager
|
import android.app.AlarmManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
|
@ -14,7 +15,9 @@ import android.widget.Toast
|
||||||
import net.osmand.PlatformUtil
|
import net.osmand.PlatformUtil
|
||||||
import net.osmand.telegram.helpers.TelegramHelper.TelegramIncomingMessagesListener
|
import net.osmand.telegram.helpers.TelegramHelper.TelegramIncomingMessagesListener
|
||||||
import net.osmand.telegram.notifications.TelegramNotification.NotificationType
|
import net.osmand.telegram.notifications.TelegramNotification.NotificationType
|
||||||
|
import net.osmand.telegram.utils.AndroidUtils
|
||||||
import org.drinkless.td.libcore.telegram.TdApi
|
import org.drinkless.td.libcore.telegram.TdApi
|
||||||
|
import java.util.ArrayList
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
class TelegramService : Service(), LocationListener, TelegramIncomingMessagesListener {
|
class TelegramService : Service(), LocationListener, TelegramIncomingMessagesListener {
|
||||||
|
@ -127,7 +130,15 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
|
||||||
stopForeground(java.lang.Boolean.TRUE)
|
stopForeground(java.lang.Boolean.TRUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun forceLocationUpdate() {
|
||||||
|
val location = getFirstTimeRunDefaultLocation()
|
||||||
|
app().shareLocationHelper.updateLocation(location)
|
||||||
|
}
|
||||||
|
|
||||||
private fun initLocationUpdates() {
|
private fun initLocationUpdates() {
|
||||||
|
val firstLocation = getFirstTimeRunDefaultLocation()
|
||||||
|
app().shareLocationHelper.updateLocation(firstLocation)
|
||||||
|
|
||||||
// requesting
|
// requesting
|
||||||
if (isContinuous()) {
|
if (isContinuous()) {
|
||||||
// request location updates
|
// 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() {
|
private fun setupAlarm() {
|
||||||
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||||
pendingIntent = PendingIntent.getBroadcast(this, 0, Intent(this, OnTelegramServiceAlarmReceiver::class.java), PendingIntent.FLAG_UPDATE_CURRENT)
|
pendingIntent = PendingIntent.getBroadcast(this, 0, Intent(this, OnTelegramServiceAlarmReceiver::class.java), PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
|
|
|
@ -72,6 +72,10 @@ class TelegramSettings(private val app: TelegramApplication) {
|
||||||
this.shareLocationChats = shareLocationChats.toHashSet()
|
this.shareLocationChats = shareLocationChats.toHashSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun stopSharingLocationToChats() {
|
||||||
|
this.shareLocationChats = emptySet()
|
||||||
|
}
|
||||||
|
|
||||||
fun showChatOnMap(chatTitle: String, show: Boolean) {
|
fun showChatOnMap(chatTitle: String, show: Boolean) {
|
||||||
val showOnMapChats = showOnMapChats.toMutableList()
|
val showOnMapChats = showOnMapChats.toMutableList()
|
||||||
if (show) {
|
if (show) {
|
||||||
|
|
|
@ -58,6 +58,8 @@ class ShareLocationHelper(private val app: TelegramApplication) {
|
||||||
app.startMyLocationService()
|
app.startMyLocationService()
|
||||||
|
|
||||||
refreshNotification()
|
refreshNotification()
|
||||||
|
} else {
|
||||||
|
app.forceUpdateMyLocation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,8 +9,8 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 14
|
minSdkVersion 15
|
||||||
targetSdkVersion 23
|
targetSdkVersion 27
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 9
|
minSdkVersion 15
|
||||||
targetSdkVersion 21
|
targetSdkVersion 27
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
|
|
|
@ -21,8 +21,8 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 9
|
minSdkVersion 15
|
||||||
targetSdkVersion 23
|
targetSdkVersion 27
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
|
|
|
@ -21,8 +21,8 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 9
|
minSdkVersion 15
|
||||||
targetSdkVersion 21
|
targetSdkVersion 27
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
|
|
|
@ -21,8 +21,8 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 9
|
minSdkVersion 15
|
||||||
targetSdkVersion 21
|
targetSdkVersion 27
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
|
|