diff --git a/OsmAnd-telegram/res/layout/bottom_sheet_disable_sharing.xml b/OsmAnd-telegram/res/layout/bottom_sheet_disable_sharing.xml
new file mode 100644
index 0000000000..abf2b7897b
--- /dev/null
+++ b/OsmAnd-telegram/res/layout/bottom_sheet_disable_sharing.xml
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml
index cc243b866e..9d81d314ed 100644
--- a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml
+++ b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml
@@ -186,6 +186,7 @@
android:id="@+id/stop_all_sharing_row"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height"
+ android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard">
@@ -207,7 +208,10 @@
+ android:layout_height="wrap_content"
+ android:background="@null"
+ android:clickable="false"
+ android:focusable="false"/>
diff --git a/OsmAnd-telegram/res/values/strings.xml b/OsmAnd-telegram/res/values/strings.xml
index b17c8b9ff2..3a547671d0 100644
--- a/OsmAnd-telegram/res/values/strings.xml
+++ b/OsmAnd-telegram/res/values/strings.xml
@@ -1,4 +1,7 @@
+ It will disable sharing your location to all selected chats (%1$d).
+ Disable all sharing
+ Turn off all
Exit
ago
Last response
diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/DisableSharingBottomSheet.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/DisableSharingBottomSheet.kt
new file mode 100644
index 0000000000..d5e0f18ab6
--- /dev/null
+++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/DisableSharingBottomSheet.kt
@@ -0,0 +1,81 @@
+package net.osmand.telegram.ui
+
+import android.os.Bundle
+import android.support.design.widget.BottomSheetBehavior
+import android.support.v4.app.DialogFragment
+import android.support.v4.app.Fragment
+import android.support.v4.app.FragmentManager
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+import net.osmand.telegram.R
+import net.osmand.telegram.ui.views.BottomSheetDialog
+
+class DisableSharingBottomSheet : DialogFragment() {
+
+ override fun onCreateDialog(savedInstanceState: Bundle?) = BottomSheetDialog(context!!)
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ val mainView = inflater.inflate(R.layout.bottom_sheet_disable_sharing, container, false)
+
+ mainView.findViewById(R.id.scroll_view_container).setOnClickListener { dismiss() }
+
+ BottomSheetBehavior.from(mainView.findViewById(R.id.scroll_view))
+ .setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
+
+ override fun onStateChanged(bottomSheet: View, newState: Int) {
+ if (newState == BottomSheetBehavior.STATE_HIDDEN) {
+ dismiss()
+ }
+ }
+
+ override fun onSlide(bottomSheet: View, slideOffset: Float) {}
+ })
+
+ mainView.findViewById(R.id.description).text =
+ getString(R.string.disable_all_sharing_desc, arguments?.getInt(CHATS_COUNT_KEY, -1))
+
+ mainView.findViewById(R.id.secondary_btn).apply {
+ setText(R.string.shared_string_cancel)
+ setOnClickListener { dismiss() }
+ }
+
+ mainView.findViewById(R.id.primary_btn).apply {
+ setText(R.string.turn_off_all)
+ setOnClickListener {
+ targetFragment?.also { target ->
+ target.onActivityResult(targetRequestCode, SHARING_DISABLED_REQUEST_CODE, null)
+ }
+ dismiss()
+ }
+ }
+
+ return mainView
+ }
+
+ companion object {
+
+ const val SHARING_DISABLED_REQUEST_CODE = 1
+
+ private const val TAG = "DisableSharingBottomSheet"
+ private const val CHATS_COUNT_KEY = "chats_count"
+
+ fun showInstance(fm: FragmentManager, target: Fragment, chatsCount: Int): Boolean {
+ return try {
+ DisableSharingBottomSheet().apply {
+ arguments = Bundle().apply { putInt(CHATS_COUNT_KEY, chatsCount) }
+ setTargetFragment(target, SHARING_DISABLED_REQUEST_CODE)
+ show(fm, TAG)
+ }
+ true
+ } catch (e: RuntimeException) {
+ false
+ }
+ }
+ }
+}
diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt
index 92ccb35ed3..bddbb04229 100644
--- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt
+++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt
@@ -178,17 +178,14 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
})
}
- stopSharingSwitcher = mainView.findViewById(R.id.stop_all_sharing_switcher).apply {
- isChecked = sharingMode
- setOnCheckedChangeListener { _, isChecked ->
- if (!isChecked) {
- sharingMode = isChecked
- activity.stopSharingLocation()
- updateContent()
- }
+ mainView.findViewById(R.id.stop_all_sharing_row).setOnClickListener {
+ fragmentManager?.also { fm ->
+ DisableSharingBottomSheet.showInstance(fm, this, adapter.chats.size)
}
}
+ stopSharingSwitcher = mainView.findViewById(R.id.stop_all_sharing_switcher)
+
startSharingBtn = mainView.findViewById(R.id.start_sharing_btn).apply {
visibility = if (sharingMode) View.VISIBLE else View.GONE
setOnClickListener {
@@ -221,10 +218,17 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
- if (requestCode == SetTimeDialogFragment.LOCATION_SHARED_REQUEST_CODE) {
- sharingMode = settings.hasAnyChatToShareLocation()
- clearSelection()
- updateContent()
+ when (requestCode) {
+ SetTimeDialogFragment.LOCATION_SHARED_REQUEST_CODE -> {
+ sharingMode = settings.hasAnyChatToShareLocation()
+ clearSelection()
+ updateContent()
+ }
+ DisableSharingBottomSheet.SHARING_DISABLED_REQUEST_CODE -> {
+ sharingMode = false
+ (activity as MainActivity).stopSharingLocation()
+ updateContent()
+ }
}
}