Add the ability to stop sharing location from "My location" screen
This commit is contained in:
parent
af7c9bed4b
commit
e3ead28f59
2 changed files with 51 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.telegram.ui
|
||||
|
||||
import android.animation.*
|
||||
import android.content.Intent
|
||||
import android.graphics.Paint
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Build
|
||||
|
@ -156,6 +157,13 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
outState.putLongArray(SELECTED_CHATS_KEY, selectedChats.toLongArray())
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == SetTimeDialogFragment.LOCATION_SHARED_REQUEST_CODE) {
|
||||
clearSelection()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTelegramStatusChanged(
|
||||
prevTelegramAuthorizationState: TelegramHelper.TelegramAuthorizationState,
|
||||
newTelegramAuthorizationState: TelegramHelper.TelegramAuthorizationState
|
||||
|
@ -195,12 +203,15 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
}
|
||||
|
||||
fun onPrimaryBtnClick() {
|
||||
activity?.supportFragmentManager?.also {
|
||||
SetTimeDialogFragment.showInstance(it, selectedChats)
|
||||
}
|
||||
val fm = fragmentManager ?: return
|
||||
SetTimeDialogFragment.showInstance(fm, selectedChats, this)
|
||||
}
|
||||
|
||||
fun onSecondaryBtnClick() {
|
||||
clearSelection()
|
||||
}
|
||||
|
||||
private fun clearSelection() {
|
||||
selectedChats.clear()
|
||||
adapter.notifyDataSetChanged()
|
||||
actionButtonsListener?.switchButtonsVisibility(false)
|
||||
|
@ -344,27 +355,43 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
override fun onBindViewHolder(holder: ChatViewHolder, position: Int) {
|
||||
val chat = chats[position]
|
||||
val lastItem = position == itemCount - 1
|
||||
val live = app.settings.isSharingLocationToChat(chat.id)
|
||||
|
||||
TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path)
|
||||
holder.title?.text = chat.title
|
||||
holder.description?.text = "Some description" // FIXME
|
||||
holder.checkBox?.apply {
|
||||
visibility = View.VISIBLE
|
||||
setOnCheckedChangeListener(null)
|
||||
isChecked = selectedChats.contains(chat.id)
|
||||
setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
selectedChats.add(chat.id)
|
||||
} else {
|
||||
selectedChats.remove(chat.id)
|
||||
if (live) {
|
||||
holder.checkBox?.visibility = View.GONE
|
||||
holder.textInArea?.visibility = View.VISIBLE
|
||||
holder.textInArea?.text = getString(R.string.shared_string_live)
|
||||
} else {
|
||||
holder.textInArea?.visibility = View.GONE
|
||||
holder.checkBox?.apply {
|
||||
visibility = View.VISIBLE
|
||||
setOnCheckedChangeListener(null)
|
||||
isChecked = selectedChats.contains(chat.id)
|
||||
setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
selectedChats.add(chat.id)
|
||||
} else {
|
||||
selectedChats.remove(chat.id)
|
||||
}
|
||||
actionButtonsListener?.switchButtonsVisibility(selectedChats.isNotEmpty())
|
||||
}
|
||||
actionButtonsListener?.switchButtonsVisibility(selectedChats.isNotEmpty())
|
||||
}
|
||||
}
|
||||
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
|
||||
holder.itemView.setOnClickListener {
|
||||
holder.checkBox?.apply {
|
||||
isChecked = !isChecked
|
||||
if (live) {
|
||||
app.settings.shareLocationToChat(chat.id, false)
|
||||
if (!app.settings.hasAnyChatToShareLocation()) {
|
||||
app.shareLocationHelper.stopSharingLocation()
|
||||
}
|
||||
notifyItemChanged(position)
|
||||
} else {
|
||||
holder.checkBox?.apply {
|
||||
isChecked = !isChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -375,6 +402,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
val icon: ImageView? = view.findViewById(R.id.icon)
|
||||
val title: TextView? = view.findViewById(R.id.title)
|
||||
val description: TextView? = view.findViewById(R.id.description)
|
||||
val textInArea: TextView? = view.findViewById(R.id.text_in_area)
|
||||
val checkBox: CheckBox? = view.findViewById(R.id.check_box)
|
||||
val bottomShadow: View? = view.findViewById(R.id.bottom_shadow)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.telegram.ui
|
|||
import android.app.TimePickerDialog
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.DialogFragment
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
|
@ -84,6 +85,9 @@ class SetTimeDialogFragment : DialogFragment() {
|
|||
settings.shareLocationToChat(chatId, true, livePeriod)
|
||||
}
|
||||
app.shareLocationHelper.startSharingLocation()
|
||||
targetFragment?.also {
|
||||
it.onActivityResult(targetRequestCode, LOCATION_SHARED_REQUEST_CODE, null)
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
@ -235,12 +239,14 @@ class SetTimeDialogFragment : DialogFragment() {
|
|||
|
||||
companion object {
|
||||
|
||||
const val LOCATION_SHARED_REQUEST_CODE = 0
|
||||
|
||||
private const val TAG = "SetTimeDialogFragment"
|
||||
private const val CHATS_KEY = "chats_key"
|
||||
private const val DEFAULT_VISIBLE_TIME_SECONDS = 60 * 60L // 1 hour
|
||||
private const val NO_VALUE = -1L
|
||||
|
||||
fun showInstance(fm: FragmentManager, chatIds: Set<Long>): Boolean {
|
||||
fun showInstance(fm: FragmentManager, chatIds: Set<Long>, target: Fragment): Boolean {
|
||||
return try {
|
||||
val chats = mutableListOf<Long>()
|
||||
for (id in chatIds) {
|
||||
|
@ -249,6 +255,7 @@ class SetTimeDialogFragment : DialogFragment() {
|
|||
}
|
||||
SetTimeDialogFragment().apply {
|
||||
arguments = Bundle().apply { putLongArray(CHATS_KEY, chats.toLongArray()) }
|
||||
setTargetFragment(target, LOCATION_SHARED_REQUEST_CODE)
|
||||
show(fm, TAG)
|
||||
}
|
||||
true
|
||||
|
|
Loading…
Reference in a new issue