Detect first location. Stop sharing if no permission. UI fix.
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,34 +1,47 @@
|
|||
<?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" />
|
||||
|
||||
<android.support.design.widget.BottomNavigationView
|
||||
android:id="@+id/bottom_navigation"
|
||||
<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:visibility="visible"
|
||||
app:itemBackground="?attr/bg_color"
|
||||
app:menu="@menu/bottom_navigation_menu"
|
||||
tools:itemIconTint="@color/ctrl_active_color_light"
|
||||
tools:itemTextColor="@color/ctrl_active_color_light"
|
||||
tools:visibility="visible" />
|
||||
android:layout_gravity="bottom"
|
||||
android:scaleType="fitXY"
|
||||
android:src="?attr/bottom_nav_shadow" />
|
||||
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
<android.support.design.widget.BottomNavigationView
|
||||
android:id="@+id/bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="visible"
|
||||
app:itemBackground="?attr/bg_color"
|
||||
app:menu="@menu/bottom_navigation_menu"
|
||||
tools:itemIconTint="@color/ctrl_active_color_light"
|
||||
tools:itemTextColor="@color/ctrl_active_color_light"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
|
@ -1,9 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<declare-styleable name="AppTheme">
|
||||
<attr name="bg_color" format="reference" />
|
||||
<attr name="icon_color" format="reference" />
|
||||
<attr name="ctrl_active_color" format="reference" />
|
||||
<attr name="ctrl_color" format="reference" />
|
||||
</declare-styleable>
|
||||
<declare-styleable name="AppTheme">
|
||||
<attr name="bg_color" format="reference" />
|
||||
<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>
|
|
@ -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">
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
@ -128,6 +131,9 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
|
|||
}
|
||||
|
||||
private fun initLocationUpdates() {
|
||||
val firstLocation = getFirstTimeRunDefaultLocation()
|
||||
app().shareLocationHelper.updateLocation(firstLocation)
|
||||
|
||||
// requesting
|
||||
if (isContinuous()) {
|
||||
// request location updates
|
||||
|
@ -146,6 +152,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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|